Re: Problem with WSH Shell Exec StdOut
- From: "Paul Randall" <paulr90@xxxxxxx>
- Date: Tue, 20 Jan 2009 13:30:06 -0700
"Pegasus (MVP)" <I.can@xxxxxxxxxx> wrote in message
news:ek$sphzeJHA.4124@xxxxxxxxxxxxxxxxxxxxxxx
"Paul Randall" <paulr90@xxxxxxx> wrote in message
news:OsENNqyeJHA.4180@xxxxxxxxxxxxxxxxxxxxxxx
"Pegasus (MVP)" <I.can@xxxxxxxxxx> wrote in message
news:%230$atZyeJHA.4528@xxxxxxxxxxxxxxxxxxxxxxx
"Paul Randall" <paulr90@xxxxxxx> wrote in message
news:O9DbWTyeJHA.4180@xxxxxxxxxxxxxxxxxxxxxxx
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
Since you already have a working single-line batch file, what might be
the purpose of creating a 15-line VB Script file to invoke it? If you
must use a VB Script, wouldn't it be more consistent to invoke
NeroCmd.exe from within the VB Script? It would certainly facilitate
installation and maintenance!
Thanks for your response.
My real script does Shell Exec indivual NeroCmds, reads the responses,
and branches accordingly, to create one or more CDs whose source files
come from 2 GB flash cards. I wanted to post the simplest example that
showed a significant difference between the real-time StdOut and what
appears in a manually invoked command line box using the identical
command. I'm hoping for help in getting info from StdOut in real time.
This would help with providing progress info to the end user. Right now,
they just get a blank black command line window; I think a 'This will
take 61 seconds.' message at the start of the process would be more
helpful, but only NeroCmd can give a reasonable estimate.
-Paul Randall
AFAIK you can't display real time output using the exec method because
your script will not move beyond the line
Set oExec = WshShell.Exec("test2b.bat")
until test2b.bat has finshed its job. When erasing a CD, this will take
some 60 seconds.
Thanks for your response. I appreciate your interest in this.
I think I disproved the theory that 'your script will not move beyond the
line ...', when I stated:
... 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.*
The echoing of the batch file's command indicates that the StdOut stream is
making that much immediately available. What I don't understand is why none
of NeroCmd.exe's output to StdOut is available until the process ends, if
the batch file or the complete NeroCmd statement is started through WSH
Shell exec. It is all displayed in real time when the batch file or NeroCmd
statement is started manually.
I wish I knew of a native WXP command line utility example that would take a
significant period over which to execute but which only sends a line of
output occasionally, so we could have a VBScript display each line from
StdOut as it occurs. Perhaps you know of something?
-Paul Randall
.
- Follow-Ups:
- Re: Problem with WSH Shell Exec StdOut
- From: ekkehard.horner
- Re: Problem with WSH Shell Exec StdOut
- From: Tom Lavedas
- Re: Problem with WSH Shell Exec StdOut
- References:
- Problem with WSH Shell Exec StdOut
- From: Paul Randall
- Re: Problem with WSH Shell Exec StdOut
- From: Pegasus \(MVP\)
- Re: Problem with WSH Shell Exec StdOut
- From: Paul Randall
- Re: Problem with WSH Shell Exec StdOut
- From: Pegasus \(MVP\)
- Problem with WSH Shell Exec StdOut
- Prev by Date: Script to choose SSID?
- Next by Date: Re: Problem with WSH Shell Exec StdOut
- Previous by thread: Re: Problem with WSH Shell Exec StdOut
- Next by thread: Re: Problem with WSH Shell Exec StdOut
- Index(es):
Relevant Pages
|
Loading