Failure of WshShellExec.StdOut.ReadAll in MM

This forum is for questions / discussions regarding development of addons / tweaks for MediaMonkey for Windows 4.

Moderators: Gurus, Addon Administrators

chrisjj
Posts: 5007
Joined: Wed Feb 14, 2007 5:14 pm
Location: UK

Failure of WshShellExec.StdOut.ReadAll in MM

Post 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 
Chris
rivorson
Posts: 594
Joined: Thu Jul 25, 2013 4:17 am

Re: Failure of WshShellExec.StdOut.ReadAll in MM

Post by rivorson »

You could probably find out why it isn't working by adding this:

Code: Select all

Case Else
    strOutput = WshShellExec.Status
chrisjj
Posts: 5007
Joined: Wed Feb 14, 2007 5:14 pm
Location: UK

Re: Failure of WshShellExec.StdOut.ReadAll in MM

Post 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.
Chris
rivorson
Posts: 594
Joined: Thu Jul 25, 2013 4:17 am

Re: Failure of WshShellExec.StdOut.ReadAll in MM

Post by rivorson »

I just tried your code and it worked perfectly on my install.

Maybe you could try

Code: Select all

MsgBox TypeName(strOutput)
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?
chrisjj
Posts: 5007
Joined: Wed Feb 14, 2007 5:14 pm
Location: UK

Re: Failure of WshShellExec.StdOut.ReadAll in MM

Post 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

Code: Select all

MsgBox TypeName(strOutput)
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.

Image

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.
Chris
rivorson
Posts: 594
Joined: Thu Jul 25, 2013 4:17 am

Re: Failure of WshShellExec.StdOut.ReadAll in MM

Post 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.
chrisjj
Posts: 5007
Joined: Wed Feb 14, 2007 5:14 pm
Location: UK

Re: Failure of WshShellExec.StdOut.ReadAll in MM

Post 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?
Chris
rivorson
Posts: 594
Joined: Thu Jul 25, 2013 4:17 am

Re: Failure of WshShellExec.StdOut.ReadAll in MM

Post 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.
chrisjj
Posts: 5007
Joined: Wed Feb 14, 2007 5:14 pm
Location: UK

Re: Failure of WshShellExec.StdOut.ReadAll in MM

Post 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

Image

then this

Image
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.
Chris
rivorson
Posts: 594
Joined: Thu Jul 25, 2013 4:17 am

Re: Failure of WshShellExec.StdOut.ReadAll in MM

Post 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.
chrisjj
Posts: 5007
Joined: Wed Feb 14, 2007 5:14 pm
Location: UK

Re: Failure of WshShellExec.StdOut.ReadAll in MM

Post 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?
Chris
Peke
Posts: 17457
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Re: Failure of WshShellExec.StdOut.ReadAll in MM

Post by Peke »

Just wondering if anyone tried RUN instead of exec and what echo report back?
Best regards,
Peke
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
Image
How to attach PICTURE/SCREENSHOTS to forum posts
chrisjj
Posts: 5007
Joined: Wed Feb 14, 2007 5:14 pm
Location: UK

Re: Failure of WshShellExec.StdOut.ReadAll in MM

Post 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?
Chris
chrisjj
Posts: 5007
Joined: Wed Feb 14, 2007 5:14 pm
Location: UK

Re: Failure of WshShellExec.StdOut.ReadAll in MM

Post 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

Image

then this

Image
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

Image Image

but a good result in cscript and wscript:

Image Image

I take this to confirm that the problem is specific to MM, and is not specific to ReadAll.
Chris
chrisjj
Posts: 5007
Joined: Wed Feb 14, 2007 5:14 pm
Location: UK

Re: Failure of WshShellExec.StdOut.ReadAll in MM

Post by chrisjj »

Further info: With the test command changed to cmd /c dir, there's no fail. Note added to OP.
Chris
Post Reply