Re: Problem with WSH Shell Exec StdOut
- From: "Paul Randall" <paulr90@xxxxxxx>
- Date: Tue, 20 Jan 2009 11:11:39 -0700
"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
.
- Follow-Ups:
- Re: Problem with WSH Shell Exec StdOut
- From: Pegasus \(MVP\)
- 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\)
- Problem with WSH Shell Exec StdOut
- Prev by Date: Re: Batch file (CMD) output into HTA
- 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