1

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.

  • 1
    The difference with the command prompt example is you're running it from the "Command Prompt" also known as `cmd.exe`, the redirection of the output is a Command Prompt feature so it works as expected. – user692942 Mar 09 '22 at 12:22
  • 1
    @Flakes yes, that helped, I was able to fix it by adding `cmd.exe /c ` in front of the `cscript` command. And @user692942 that makes sense, now I understand it. Thanks to both! Unfortunately I don't have enough reputation to upvote your comments, but I would be glad to accept an answer. – Benjamin Krausse DB Mar 10 '22 at 10:08
  • 2
    @BenjaminKrausseDB glad that helped but, to be honest, would suggest you accept the duplicate as it already answered the question. – user692942 Mar 10 '22 at 10:34
  • 1
    OK, just did that. – Benjamin Krausse DB Mar 11 '22 at 14:07

0 Answers0