Why can't I redirect error output from cscript to a text file when I'm calling it from another VBScript?

53 Views Asked by At

Alright, so I'm pulling my hair out over this one. I have a VBScript that calls other VBScripts, and I need it to output the errors to text files, since the scripts should be running non-interactively. Oddly enough, though, it doesn't work.

I'm able to reproduce it with two VBS files:

thisshouldfail.vbs

Dim Failtest
Failtest = WScript.Arguments.Item(5) 'This line generates an index out of bounds error, since there are no arguments being passed

testerrorlog.vbs

Set oShell = CreateObject("WScript.Shell")
oShell.Run "thisshouldfail.vbs" 'gives me a window with an error message
oShell.Run "cscript thisshouldfail.vbs 2>> D:\Errorlog.txt" 'doesn't do anything

Oddly enough, if I take the same thing and put it into the command prompt:

cscript thisshouldfail.vbs 2>> D:\Errorlog.txt

Then it outputs the error log to the text file correctly. What am I doing wrong? Dr. Google hasn't helped much here.

0

There are 0 best solutions below