Failure of WshShellExec.StdOut.ReadAll in MM

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

Moderator: Gurus

Failure of WshShellExec.StdOut.ReadAll in MM

Postby chrisjj » Wed Oct 19, 2016 5:35 pm

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

Re: Failure of WshShellExec.StdOut.ReadAll in MM

Postby rivorson » Wed Oct 19, 2016 5:51 pm

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

Code: Select all
Case Else
    strOutput = WshShellExec.Status
rivorson
 
Posts: 526
Joined: Thu Jul 25, 2013 4:17 am

Re: Failure of WshShellExec.StdOut.ReadAll in MM

Postby chrisjj » Wed Oct 19, 2016 6:38 pm

It isn't executed. The status is 1 - as expected. The .Exec is succeeding. The fail is of WshShellExec.StdOut.ReadAll.

OP clarified.
Chris
chrisjj
 
Posts: 4926
Joined: Wed Feb 14, 2007 5:14 pm
Location: UK

Re: Failure of WshShellExec.StdOut.ReadAll in MM

Postby rivorson » Thu Oct 20, 2016 3:56 am

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

Re: Failure of WshShellExec.StdOut.ReadAll in MM

Postby chrisjj » Thu Oct 20, 2016 4:58 am

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

Re: Failure of WshShellExec.StdOut.ReadAll in MM

Postby rivorson » Thu Oct 20, 2016 6:55 am

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
 
Posts: 526
Joined: Thu Jul 25, 2013 4:17 am

Re: Failure of WshShellExec.StdOut.ReadAll in MM

Postby chrisjj » Thu Oct 20, 2016 12:39 pm

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

Re: Failure of WshShellExec.StdOut.ReadAll in MM

Postby rivorson » Thu Oct 20, 2016 1:29 pm

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

Re: Failure of WshShellExec.StdOut.ReadAll in MM

Postby chrisjj » Thu Oct 20, 2016 5:29 pm

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

Re: Failure of WshShellExec.StdOut.ReadAll in MM

Postby rivorson » Thu Oct 20, 2016 7:23 pm

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
 
Posts: 526
Joined: Thu Jul 25, 2013 4:17 am

Re: Failure of WshShellExec.StdOut.ReadAll in MM

Postby chrisjj » Thu Oct 20, 2016 8:15 pm

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

Re: Failure of WshShellExec.StdOut.ReadAll in MM

Postby Peke » Thu Oct 20, 2016 9:30 pm

Just wondering if anyone tried RUN instead of exec and what echo report back?
Best regards,
Pavle
MM Core Developer and Admin of free MediaMonkey extensions Hosting
Image
Image
Peke
 
Posts: 10409
Joined: Tue Jun 10, 2003 7:21 pm
Location: Serbia

Re: Failure of WshShellExec.StdOut.ReadAll in MM

Postby chrisjj » Fri Oct 21, 2016 5:35 am

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: 4926
Joined: Wed Feb 14, 2007 5:14 pm
Location: UK

Re: Failure of WshShellExec.StdOut.ReadAll in MM

Postby 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

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: 4926
Joined: Wed Feb 14, 2007 5:14 pm
Location: UK

Re: Failure of WshShellExec.StdOut.ReadAll in MM

Postby chrisjj » Fri Oct 21, 2016 6:22 am

Further info: With the test command changed to cmd /c dir, there's no fail. Note added to OP.
Chris
chrisjj
 
Posts: 4926
Joined: Wed Feb 14, 2007 5:14 pm
Location: UK

Next

Return to MediaMonkey 4 Addons developer forum

Who is online

Users browsing this forum: No registered users and 7 guests