Re: STDERR and STDOUT redirection from within a vbs script

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: Steve Fulton (cerberus40_at_hotmail.com)
Date: 01/28/05


Date: Fri, 28 Jan 2005 09:29:43 -0500

wrote:

> Hello,
>
> I have to use some vbs script, lauching them from within another
> application i'm coding in err ... another language :)
>
> Is there a simple way to force redirection of STDOUT and STDERR from
> within the vbs script ?
>
> That is I'm looking for some instructions to add at the begining of the
> vbs script, that will take 2 filenames as arguments and afterwards
> redirect the stderr and stdout to these files.
>
> The point here is that i do not want to use some command line
> redirection . Also, i do not want to mess with the rest of the script,
> i just want the standard streams to be redirected.

What you want probably can't be done.

The only way to redirect the streams without command line redirection or
changing the script would involve invoking the script with some host method
similar to WshShell.Exec that captures them itself. Since you don't say
what host you're using, we can't say if this is possible.

Changing the script involves hooking file handles into either the StdOut
and StdErr streams or text files:

   Set FSO = CreateObject("Scripting.FileSystemObject")
   Set Args = WScript.Arguments
   If Args.Count = 0 Then
     Set MyStdOut = WScript.StdOut
   Else
     ' You probably want more robust error handling here ;-)
     Set MyStdOut = FSO.OpenTextFile(Args.Item(0),2,True)
   End If

   ' Use MyStdOut instead of WScript.StdOut
   MyStdOut.WriteLine "Hello, World!"

And, of course, there's command line redirection.

-- 
Steve
The most perfect technique is that which is not noticed at all.
-Pablo Casals


Relevant Pages

  • FAQ 8.25 How can I capture STDERR from an external command?
    ... This message is one of several periodic postings to comp.lang.perl.misc ... both STDOUT and STDERR will go the same place as the ... script's STDOUT and STDERR, unless the systemcommand redirects them. ... You can also use file-descriptor redirection to make STDERR a duplicate ...
    (comp.lang.perl.misc)
  • FAQ 8.25 How can I capture STDERR from an external command?
    ... This message is one of several periodic postings to comp.lang.perl.misc ... both STDOUT and STDERR will go the same place as the ... script's STDOUT and STDERR, unless the systemcommand redirects them. ... You can also use file-descriptor redirection to make STDERR a duplicate ...
    (comp.lang.perl.misc)
  • FAQ 8.25 How can I capture STDERR from an external command?
    ... This message is one of several periodic postings to comp.lang.perl.misc ... both STDOUT and STDERR will go the same place as the ... script's STDOUT and STDERR, unless the systemcommand redirects them. ... You can also use file-descriptor redirection to make STDERR a duplicate ...
    (comp.lang.perl.misc)
  • FAQ 8.25 How can I capture STDERR from an external command?
    ... both STDOUT and STDERR will go the same place as the ... script's STDOUT and STDERR, unless the systemcommand redirects them. ... You can also use file-descriptor redirection to make STDERR a duplicate ... The first command sends both standard out and standard error to the ...
    (comp.lang.perl.misc)
  • FAQ 8.25 How can I capture STDERR from an external command?
    ... both STDOUT and STDERR will go the same place as the ... script's STDOUT and STDERR, unless the systemcommand redirects them. ... You can also use file-descriptor redirection to make STDERR a duplicate ... The first command sends both standard out and standard error to the ...
    (comp.lang.perl.misc)