In cscript.exe and wscript.exe it works - the MsgBox shows command output. In MM, the MsgBox shows nothing. EDIT: In both cases, the final status is WshFinished, so the fail is in WshShellExec.StdOut.ReadAll . Does MM perhaps prang StdOut?
EXIT: With slow ping 127.0.0.1 replaced by fast cmd /c dir there's no fail: http://i.imgur.com/zFSNz32.png , perhaps suggesting the fail is time-sensitive.
I executed mine from the MM script menu, same as yours but I don't have a keyboard shortcut assigned.
I'm running Windows 10 Pro 64 bit. It could possibly be something in the wscript.exe version, found in C:\Windows\System32. I have version 5.812.10240.16384. I don't think the version would make a difference for this particular command but I can't think of anything else to try.
rivorson wrote:I executed mine from the MM script menu, same as yours but I don't have a keyboard shortcut assigned.
Thanks.
Here with key assignment removed, the problem remains.
Likewise with ScriptType changed to 0.
rivorson wrote:I'm running Windows 10 Pro 64 bit. It could possibly be something in the wscript.exe version, found in C:\Windows\System32. I have version 5.812.10240.16384. I don't think the version would make a difference for this particular command but I can't think of anything else to try.
I have 5.8.7600.16385. On Windows 7 64-bit. MM build is latest - 1813.
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.
Have you tried reading the output line by line instead of ReadAll?
Dim line, linecount
Do
line = objExec.StdOut.ReadLine()
strOutput = strOutput & line & vbcrlf
linecount = linecount+1
Loop While Not WshShellExec.Stdout.atEndOfStream
MsgBox strOutput
MsgBox linecount
I put the linecount in for extra diagnosis so you can see if you get a single empty line or multiple empty lines.
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.
So the WshShellExec.Stdout just isn't giving any result.
The only thing left that I can suggest is creating a fresh portable install of MM to see if it does the same. You could also try the portable install on another computer if you have access to one to see if the problem is specific to your computer.
rivorson wrote:The only thing left that I can suggest is creating a fresh portable install of MM to see if it does the same.
"When I take that code out of the SUB and give it to cscript.exe or wscript.exe, I get the same." suggest you were right in suggesting this is not down to MM.
Or does cscript.exe or wscript.exe give different there?
Peke wrote:Just wondering if anyone tried RUN instead of exec
Run doesn't return an object, so provides no access to StdOut. (Literally replacing Exec with Run fails with "Error #424 - Microsoft VBScript runtime error
Object required: 'WshShell.Run(...)'".
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.
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.