Problem with WSH Shell Exec StdOut

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I'm trying to Use WSH Shell Exec to run a 'command line' program and catch
its StdOut stream in real time. I'm using Nero's NeroCmd.exe to read,
write, erase, and get info about a CD-RW in drive F:. I'm running WXP Pro
SP2. NeroCmd.exe is a command line utility included with or usable with
most versions of Nero in the past 5 or more years, including the free
versions included with many CD/DVD writers, I think.

If I create and run a .bat file with the following on a single line:
C:\WINDOWS\system32\cmd.exe /c "C:\Program Files\Nero\Nero
7\Core\NeroCmd.exe" --erase -- drivename f

then almost immediately I get a command window displaying the following:
C:\Program Files\Windows Resource Kits\Tools>%comspec% /c "C:\Pr\Nero
7\Core\NeroCmd.exe" --erase --drivename f
Erasing disc. This will take 61 seconds.

and after about a minute an "OK." message appears and the command window
closes.

The batch file runs differently if Shell Exec'ed.
Here is the script I'm currently using:
'-------------
Dim WshShell, oExec, input
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("test2b.bat")

Do While True
input = "At End Of Stream!"
Do while Not oExec.StdOut.AtEndOfStream
input = Replace(input, "At End Of Stream!", "")
input = input & oExec.StdOut.Read(1)
'Display each line as it is received.
If InStr(input, vbcrlf) <> 0 Then Exit Do
WScript.Sleep 0
Loop
MsgBox "*" & input & "*"
WScript.Sleep 10
Loop
'-------------

Sorry about the endless loop. You have to abort the script by ending the
wscript.exe in windows task manager.

If I use the VBScript above to use the shell object's exec method to run the
script, and to read and display the exec method's StdOut stream in real
time, I immediately get the following:

1: a message box with two asterisks indicating a vbCrLf was received.

2: a message box containing the command:
*C:\Documents and Settings\Paul\My Documents\vbScript\Nero Command
Line>C:\WINDOWS\system32\cmd.exe /c "C:\Program Files\Nero\Nero
7\Core\NeroCmd.exe" --erase --drivename f *

3. after about a minute, I get two more message boxes:

*Erasing disc. This will take 61 seconds.*

and

*Ok.*

and an infinite number of *At End Of Stream!* messages.

To me, this indicates that I am not getting StdOut in real time; the 'this
will take 61 seconds' should have occurred almost immediately rather than
after the erase process was about done.

Is there some change I can make to the script to get the info in real time,
or is it likely that NeroCmd.exe handles StdOut differently when its batch
file is Shell Exec'ed than when run in a plain command line window, and I
just have to live with it?

Thanks for any help you can give me.

-Paul Randall


.



Relevant Pages

  • Re: Problem with WSH Shell Exec StdOut
    ... its StdOut stream in real time. ... then almost immediately I get a command window displaying the following: ... You have to abort the script by ending the ...
    (microsoft.public.scripting.vbscript)
  • Re: Problem with WSH Shell Exec StdOut
    ... catch its StdOut stream in real time. ...
    (microsoft.public.scripting.vbscript)
  • Bash-4.0 available for FTP
    ... Unlike previous bash distributions, this tar file includes the formatted ... The shell has been changed to be more ... rigorous about parsing commands inside command substitutions, ... Changes have been made to the Readline library being released at ...
    (gnu.announce)
  • Why newbies dont RTFM...
    ... Even though I've used Linux before, I've never had to do any ... BASH BUILTIN COMMANDS ... last command exited within ... unless the shell is not exeâ ...
    (comp.os.linux.misc)
  • Re: Great SWT Program
    ... None of the nasty things that you have said or implied about me are at ... treat the file as input (manually invoking the command interpreter ... script, copy the line into that within the editor, exit, and invoke ... the shell script. ...
    (comp.lang.java.programmer)