by chrisjj » Fri Oct 21, 2016 5:49 am
chrisjj wrote:Thanks. With some necessary adjustment:
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)
WHILE WshShellExec.Status = 0
WEND
Select Case WshShellExec.Status
Case WshFinished
strOutput = WshShellExec.StdOut.ReadAll
Case WshFailed
strOutput = WshShellExec.StdErr.ReadAll
End Select
strOutput = ""
Dim line, linecount
Do
line = WshShellExec.StdOut.ReadLine()
strOutput = strOutput & line & vbcrlf
linecount = linecount+1
Loop While Not WshShellExec.Stdout.atEndOfStream
MsgBox strOutput
MsgBox linecount
END SUB
I get this
then this
rivorson wrote:My MM is also 1813 but I don't think MM is the problem. Seems more likely to me that there's something causing the Windows Scripting Host to return the empty string.
When I take that code out of the SUB and give it to cscript.exe or wscript.exe, I get the same.
Whops. Please ignore that. I inserted your added code WITHOUT removing the ReadAll, so the results are invalid.
Inserting it correctly:
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)
WHILE WshShellExec.Status = 0
WEND
Select Case WshShellExec.Status
Case WshFinished
strOutput = ""
Dim line, linecount
Do
line = WshShellExec.StdOut.ReadLine()
strOutput = strOutput & line & vbcrlf
linecount = linecount+1
Loop While Not WshShellExec.Stdout.atEndOfStream
Case WshFailed
strOutput = WshShellExec.StdErr.ReadAll
End Select
MsgBox strOutput
MsgBox linecount
END SUB
I get the same bad result in MM
but a good result in cscript and wscript:
I take this to confirm that the problem is specific to MM, and is not specific to ReadAll.
[quote="chrisjj"]Thanks. With some necessary adjustment:
[code]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)
WHILE WshShellExec.Status = 0
WEND
Select Case WshShellExec.Status
Case WshFinished
strOutput = WshShellExec.StdOut.ReadAll
Case WshFailed
strOutput = WshShellExec.StdErr.ReadAll
End Select
strOutput = ""
Dim line, linecount
Do
line = WshShellExec.StdOut.ReadLine()
strOutput = strOutput & line & vbcrlf
linecount = linecount+1
Loop While Not WshShellExec.Stdout.atEndOfStream
MsgBox strOutput
MsgBox linecount
END SUB[/code]
I get this
[img]http://i.imgur.com/jxxMDBi.png[/img]
then this
[img]http://i.imgur.com/pXs2tVv.png[/img]
[quote="rivorson"]My MM is also 1813 but I don't think MM is the problem. Seems more likely to me that there's something causing the Windows Scripting Host to return the empty string.[/quote]
When I take that code out of the SUB and give it to cscript.exe or wscript.exe, I get the same.[/quote]
Whops. Please ignore that. I inserted your added code WITHOUT removing the ReadAll, so the results are invalid.
Inserting it correctly:
[code]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)
WHILE WshShellExec.Status = 0
WEND
Select Case WshShellExec.Status
Case WshFinished
strOutput = ""
Dim line, linecount
Do
line = WshShellExec.StdOut.ReadLine()
strOutput = strOutput & line & vbcrlf
linecount = linecount+1
Loop While Not WshShellExec.Stdout.atEndOfStream
Case WshFailed
strOutput = WshShellExec.StdErr.ReadAll
End Select
MsgBox strOutput
MsgBox linecount
END SUB[/code]
I get the same bad result in MM
[img]http://i.imgur.com/PR0T4eG.png[/img] [img]http://i.imgur.com/fvmsrQL.png[/img]
but a good result in cscript and wscript:
[img]http://i.imgur.com/jzmjHy9.png[/img] [img]http://i.imgur.com/SFOA9jT.png[/img]
I take this to confirm that the problem is specific to MM, and is not specific to ReadAll.