Re: Failure of WshShellExec.StdOut.ReadAll in MM
Posted: Fri Oct 21, 2016 7:01 am
If it works for cmd but not for ping then the only thing I can think of is that something else is reading the StdOut before your script gets to it, or possibly that the StdOut for the ping command is being redirected. Try reading the StdOut more immediately rather than waiting for the command to finish.
Alternatively try the Run command as Peke suggests. Although it doesn't give direct access to the StdOut you can redirect the output to a file and then read from the file.
https://stackoverflow.com/questions/569 ... ing-output
Code: Select all
SUB CJtest
DIM strCommand, WshShell, WshShellExec, strOutput
Const WshFinished = 1
Const WshFailed = 2
strCommand = "ping.exe 127.0.0.1"
Set WshShell = CreateObject("WScript.Shell")
Set WshShellExec = WshShell.Exec(strCommand)
On Error Resume Next
Dim line, linecount
WHILE WshShellExec.Status = 0
line = vbNullString
line = WshShellExec.StdOut.ReadLine()
If line <> vbNullString Then
strOutput = strOutput & line & vbCrLf
linecount = linecount + 1
End If
WEND
Select Case WshShellExec.Status
Case WshFinished
Do
line = WshShellExec.StdOut.ReadLine()
If line <> vbNullString Then
strOutput = strOutput & line & vbCrLf
linecount = linecount + 1
End If
Loop While Not WshShellExec.Stdout.atEndOfStream
Case WshFailed
strOutput = WshShellExec.StdErr.ReadAll
End Select
MsgBox strOutput
MsgBox linecount
END SUB
https://stackoverflow.com/questions/569 ... ing-output