Currently, if I run a vbs script I maintain my own log of the course of
execution. However, it would be better if I can write this to the stdErr
stream provided.
Microsoft says that only the cscript appplication has access to this stream
- however the Wscript app is the default host for a vbs script. So, by
default, the scripts do not have access to this stream.
That makes no sense to me. Is there some kind of workaround for this? I'm
thinking that maybe it is possible to instantiate another Shell and run the
cscript.exe and somehow access stdErr. Has anyone done this or do I just
have to be content writing to my own logs.
Thanks in advance,
Chris (ct...@aol.com)
The "C" in cscript stands for "Console" where as the "W" in wscript
stands for "Windows". Stdout and stderr are stream outputs, which
implies a console mode. There is no console in a GUI, hence here
is no room for these streams. I recommend you try it for yourself
and watch what happens with cscript.exe and with wscript.exe:
Set fso = CreateObject ("Scripting.FileSystemObject")
Set stdout = fso.GetStandardStream (1)
Set stderr = fso.GetStandardStream (2)
stdout.WriteLine "Hello, VBScript."
stderr.WriteLine "I could write an error here."
You will find the same with all other applications: A console
application (e.g. xcopy.exe) has access to these output streams
but a GUI such as Excel.exe does not.
I appreciate the prompt reply, but I am not sure I agree that a stream
output implies a console application. Any windows process should be able to
access the stderr stream provided by the environment.
I guess one way around this is to have the command which launches the script
include cscript.exe rather than let the default wscript host start up. Or if
that causes problems you can use visual basic instead of vb script. It just
bothers me that this seemingly trivial task is not available in the default
windows script host.
Thanks again and Best Regards,
Chris
You can either reenter your script under cscript, using the
WScript.Shell Run method, or open a command line console window. But
in my mind, sending errors to the StdErr device only makes sense for
logging if they are redirected into a file. In that case, writing
directly to the log makes more sense to me.
Or maybe you are really interested in getting the errors to go to an
'event log'. In that case, look at the documentation for
WScript.Shell LogEvent method instead.
WSH 5.6 documentation download (URL all one line)
http://www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en
Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
Hi, Chris
I think there is confusion as to what you actually want.
WScript is the default host for scripts, but that default can easily
be changed.
From a command window, many applications can give you some help info
by adding a /? after the executable's name like this:
C:\Documents and Settings\Paul>cscript /?
...
//H:CScript Changes the default script host to CScript.exe
//H:WScript Changes the default script host to WScript.exe (default)
Did you just want to make CScript the default host?
-Paul Randall