"R.Wieser" <add...@not.available> wrote
| I'm running a console-based windows program, and need to capture its
output.
| When I try to use the "exec" method than, nomatter what I try, something
| locks up.
|
| My code is basically this:
|
| Set oExec = WshShell.Exec(sCmd)
| Do While oExec.Status = 0
| WScript.Sleep 100
| wscript.echo oExec.stdout.readall
| Loop
|
| As the program also outputs on stderr I've changed the above reading of
| stdout with
|
| if not oExec.stdout.atendofstream then wscript.echo
oExec.stdout.read(1000)
| if not oExec.stderr.atendofstream then wscript.echo
oExec.stderr.read(1000)
|
| But no matter what I've tried (small buffers, large buffers), at some
point
| in the output it locks up. :-(
I'm not sure I have an answer, but this is a function
I've also had trouble with. I wrote an HTA to wrap
youtube-dl and would like to get it to print an update
to the HTA window as it progresses. But no matter what
I do, I can't get it to update the HTA UI.
However, I've never seen it lock up. For what it's worth,
this is my current code:
'......
Set ObjExec = SH.Exec(s1)
s1 = ""
While (ObjExec.Status = 0)
SleepEx 100
s1 = s1 & ObjExec.StdOut.ReadAll
s2 = s2 & ObjExec.StdErr.ReadAll
TReport.value = s1 & vbCrLf & s2
DoEvents
Wend
s1 = s1 & ObjExec.StdOut.ReadAll
s2 = s2 & ObjExec.StdErr.ReadAll
TReport.value = s1 & vbCrLf & s2
Set ObjExec = Nothing
'......
Sub SleepEx(Lms)
Dim Ret
Ret = SH2.Run("sleeper.vbs " & Lms, , True)
End Sub
Sub DoEvents()
SH.run "%comspec% /c exit", 0, True
End Sub
'....
Sleeper.vbs is just this:
Dim Arg
on error resume next
Arg = WScript.Arguments(0)
wscript.sleep Arg
SleepEx and DoEvents were added to try to make
the HTA update during the process, but it doesn't
work. Only after the whole thing is finished does
the command window disappear and the total output
text appears in the window. Would such pauses help
you? I don't know. Maybe it depends on the executable?
I have seen a lockup occasionally with youtube-dl.
I've assumed it's a problem with the download itself.
Maybe it got interrupted and youtube-dl couldn't
continue. I don't know. When I see that downloading
has stopped I just run the command again and it picks
up where it left off. But that problem is intermittent.