Re: Problem with WSH Shell Exec StdOut




"Tom Lavedas" <tglbatch@xxxxxxx> wrote in message
news:688e9959-bc5c-4c7d-a0b5-2f76f3b903a6@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Jan 20, 1:11 pm, "Paul Randall" <paul...@xxxxxxx> wrote:
"Pegasus (MVP)" <I....@xxxxxxxxxx> wrote in message

news:%230$atZyeJHA.4528@xxxxxxxxxxxxxxxxxxxxxxx









"Paul Randall" <paul...@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

Redirect the output into a text file to prove that there is in fact a
CR LF combination after the

Erasing disc. This will take 61 seconds.

line of text. My guess is that its LF CR or something else.

Also, why not change this line ...

Do While True

to

Do While oExec.Status = 0

I'd also consider reading the text into a character variable which is
displayed after each cycle through the inner Do loop, something like
this ...

set oCON = createobject("scripting.filesystemobject").open("con",8)

Do While True
input = "At End Of Stream!"
Do while Not oExec.StdOut.AtEndOfStream
input = Replace(input, "At End Of Stream!", "") ' why not just "" ?
c = oExec.StdOut.Read(1)
oCON.Write c
'input = input & c
'Display each line as it is received.
If ASC(c) = 10 or ASC(c) = 13 Then Exit Do
WScript.Sleep 10 ' was this a typo?
Loop
'MsgBox "*" & input & "*"
WScript.Sleep 10
Loop

Run this from the command prompt with CSCRIPT.exe to test.

Tom Lavedas
***********
http://there.is.no.more/tglbatch/

------------------------------------------------------------
Thanks, Tom
I will try your ideas and get back with my results.
My silly 'Do While True' is just a cut and paste from one of the VBScript
examples in the scripting help file.

-Paul Randall


.



Relevant Pages

  • Re: Problem with WSH Shell Exec StdOut
    ... catch its StdOut stream in real time. ...  NeroCmd.exe is a command line utility included ... Here is the script I'm currently using: ...
    (microsoft.public.scripting.vbscript)
  • Re: Problem with WSH Shell Exec StdOut
    ... catch its StdOut stream in real time. ... NeroCmd.exe is a command line utility included ... run the script, and to read and display the exec method's StdOut ...
    (microsoft.public.scripting.vbscript)
  • Re: Problem with WSH Shell Exec StdOut
    ... catch 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. ... NeroCmd.exe is a command line utility included ... Here is the script I'm currently using: ...
    (microsoft.public.scripting.vbscript)
  • 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)

Loading