Page 1 of 2
Failure of WshShellExec.StdOut.ReadAll in MM
Posted: Wed Oct 19, 2016 5:35 pm
by chrisjj
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.
Code: Select all
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
MsgBox strOutput
Re: Failure of WshShellExec.StdOut.ReadAll in MM
Posted: Wed Oct 19, 2016 5:51 pm
by rivorson
You could probably find out why it isn't working by adding this:
Code: Select all
Case Else
strOutput = WshShellExec.Status
Re: Failure of WshShellExec.StdOut.ReadAll in MM
Posted: Wed Oct 19, 2016 6:38 pm
by chrisjj
It isn't executed. The status is 1 - as expected. The .Exec is succeeding. The fail is of WshShellExec.StdOut.ReadAll.
OP clarified.
Re: Failure of WshShellExec.StdOut.ReadAll in MM
Posted: Thu Oct 20, 2016 3:56 am
by rivorson
I just tried your code and it worked perfectly on my install.
Maybe you could try
to check that the value being returned is a string. If it returns something other than a string then it could suggest where to look next.
Also, do you have any error handling in your script or is the snippet you've posted the entire script?
Re: Failure of WshShellExec.StdOut.ReadAll in MM
Posted: Thu Oct 20, 2016 4:58 am
by chrisjj
rivorson wrote:I just tried your code and it worked perfectly on my install.
Wow! Good to know. Thanks.
rivorson wrote:Maybe you could try
to check that the value being returned is a string. If it returns something other than a string then it could suggest where to look next.
It says "String".
rivorson wrote:Also, do you have any error handling in your script or is the snippet you've posted the entire script?
Entire script.
I execute it via a command key or from a menu command. The result is the same. A zero-length String.
I'd love to know how you are executing it such that it works.
I'm using Win 7 64-bit.
Re: Failure of WshShellExec.StdOut.ReadAll in MM
Posted: Thu Oct 20, 2016 6:55 am
by rivorson
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.
Re: Failure of WshShellExec.StdOut.ReadAll in MM
Posted: Thu Oct 20, 2016 12:39 pm
by chrisjj
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.
What's your MM build?
Re: Failure of WshShellExec.StdOut.ReadAll in MM
Posted: Thu Oct 20, 2016 1:29 pm
by 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.
Have you tried reading the output line by line instead of ReadAll?
Code: Select all
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.
Re: Failure of WshShellExec.StdOut.ReadAll in MM
Posted: Thu Oct 20, 2016 5:29 pm
by chrisjj
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.
Re: Failure of WshShellExec.StdOut.ReadAll in MM
Posted: Thu Oct 20, 2016 7:23 pm
by rivorson
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.
Re: Failure of WshShellExec.StdOut.ReadAll in MM
Posted: Thu Oct 20, 2016 8:15 pm
by chrisjj
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?
Re: Failure of WshShellExec.StdOut.ReadAll in MM
Posted: Thu Oct 20, 2016 9:30 pm
by Peke
Just wondering if anyone tried RUN instead of exec and what echo report back?
Re: Failure of WshShellExec.StdOut.ReadAll in MM
Posted: Fri Oct 21, 2016 5:35 am
by chrisjj
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(...)'".
Peke wrote:and what echo report back?
I don't understand this. Could you clarify?
Re: Failure of WshShellExec.StdOut.ReadAll in MM
Posted: Fri Oct 21, 2016 5:49 am
by chrisjj
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.
Re: Failure of WshShellExec.StdOut.ReadAll in MM
Posted: Fri Oct 21, 2016 6:22 am
by chrisjj
Further info: With the test command changed to cmd /c dir, there's no fail. Note added to OP.