Hello!
I'm working on a script using the WshShell.Exec() method.
To avoid buffer overflow problem (if I read the whole StdOut at the
end of the execution, sometimes my script hangs) I found a suggestion
on the "Hey, Scripting Guy!" MS blog: use a StdOut.ReadAll inside the
waiting loop.
But please notice these two examples:
-- Ex1, without ReadAll --
Dim elapsedSecs
elapsedSecs = 0
Dim quit
quit = False
Dim objShell
Set objShell = CreateObject("WScript.Shell")
Dim objCmd
Set objCmd = objShell.Exec("ping 10.113.203.200")
Do While quit = False
If objCmd.Status = 1 Then
quit = True
Else
WScript.Sleep 100
elapsedSecs = elapsedSecs + 0.1
End If
Loop
WScript.Echo "Elapsed seconds: " & elapsedSecs
-- output: "Elapsed seconds: 2,8"
-- Ex2, with ReadAll --
Dim elapsedSecs
elapsedSecs = 0
Dim quit
quit = False
Dim objShell
Set objShell = CreateObject("WScript.Shell")
Dim objCmd
Set objCmd = objShell.Exec("ping 10.113.203.200")
Do While quit = False
If Not objCmd.StdOut.AtEndOfStream Then
outBuffer = outBuffer & objCmd.StdOut.ReadAll
End If
If objCmd.Status = 1 Then
quit = True
Else
WScript.Sleep 100
elapsedSecs = elapsedSecs + 0.1
End If
Loop
WScript.Echo "Elapsed seconds: " & elapsedSecs
-- output: "Elapsed seconds: 0"
It seems ReadAll is blocking my loop until the objCmd exits... why?
thanks!


