Failure of WshShellExec.StdOut.ReadAll in MM

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

Moderator: Gurus

Re: Failure of WshShellExec.StdOut.ReadAll in MM

Postby rivorson » Fri Oct 21, 2016 7:01 am

If it works for cmd but not for ping then the only thing I can think of is that something else is reading the StdOut before your script gets to it, or possibly that the StdOut for the ping command is being redirected. Try reading the StdOut more immediately rather than waiting for the command to finish.

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)

On Error Resume Next
Dim line, linecount
WHILE WshShellExec.Status = 0
   line = vbNullString
   line = WshShellExec.StdOut.ReadLine()
   If line <> vbNullString Then
       strOutput = strOutput & line & vbCrLf
      linecount = linecount + 1
   End If
WEND

Select Case WshShellExec.Status
    Case WshFinished
        Do
            line = WshShellExec.StdOut.ReadLine()
            If line <> vbNullString Then
            strOutput = strOutput & line & vbCrLf
            linecount = linecount + 1
         End If
        Loop While Not WshShellExec.Stdout.atEndOfStream
    Case WshFailed
        strOutput = WshShellExec.StdErr.ReadAll
End Select

MsgBox strOutput

MsgBox linecount

END SUB


Alternatively try the Run command as Peke suggests. Although it doesn't give direct access to the StdOut you can redirect the output to a file and then read from the file.
https://stackoverflow.com/questions/569 ... ing-output
rivorson
 
Posts: 526
Joined: Thu Jul 25, 2013 4:17 am


Re: Failure of WshShellExec.StdOut.ReadAll in MM

Postby chrisjj » Sat Oct 22, 2016 7:17 am

rivorson wrote:If it works for cmd but not for ping then the only thing I can think of is that something else is reading the StdOut before your script gets to it, or possibly that the StdOut for the ping command is being redirected. Try reading the StdOut more immediately rather than waiting for the command to finish.


That code (http://pastebin.com/aRPkRj8Z) shows the same fail:

Image (linecount is now unfilled) then Image

rivorson wrote:Alternatively try the Run command as Peke suggests. Although it doesn't give direct access to the StdOut you can redirect the output to a file and then read from the file.


StdOut to file is what I'm using in production at the moment, but since I now want to move to parallel processes, that will require messy recoding for multiple output files (and for StdErr too) which hoping to avoid it by capturing output from WshShellExec. Thanks for the suggestion though. It remains my fallback option.
Chris
chrisjj
 
Posts: 4926
Joined: Wed Feb 14, 2007 5:14 pm
Location: UK

Re: Failure of WshShellExec.StdOut.ReadAll in MM

Postby chrisjj » Sat Oct 22, 2016 12:36 pm



Thanks. Unfortunately those solutions fail here, because they need the Wscript object which is unavailable in MM scripts. e.g. this solution http://web.archive.org/web/201610221725 ... =1%2383650 fails, when run direct in an auto script:

Image

or inside the runner you proposed at https://archive.is/VImY8#selection-813.0-813.19 :

Image
Chris
chrisjj
 
Posts: 4926
Joined: Wed Feb 14, 2007 5:14 pm
Location: UK

Previous

Return to MediaMonkey 4 Addons developer forum

Who is online

Users browsing this forum: No registered users and 4 guests