It seems so :P
I've been fighting with pipes for a while, and google says I'm in good company - it's messy. After a lot of testing, it seems PeekNamedPipe is the best way to decide when to leave the read loop, so the new
Launch$() uses this internally.
The sample below launches a console app that returns strings
unsteadily, i.e. normally it takes around 50ms to see the next output, but occasionally it chokes for a whole second. This is a typical behaviour e.g. of archivers, and the coder must impose a timeout to decide if the delay is OK or if the child process hangs. In other words, the third arg of
Launch$() is now the tolerated inactivity period:
include \masm32\MasmBasic\MasmBasic.inc ;
download Init PrintLine "## Launching SlowPrint.exe ##"
; slowprint.exe must be in the same folder Let esi=
Launch$("SlowPrint", SW_MINIMIZE, 1000)
; max allowed inactive period of child process is 1000ms PrintLine Str$("\nFirst attempt, timeout=1000:
exit code=%i\n",
ExitCode(
$)), "Output:", Tb$, esi
Let esi=
Launch$("SlowPrint", SW_MINIMIZE, 1020)
PrintLine Str$("\nSecond attempt, timeout=1020:
exit code=%i\n",
ExitCode(
$)), "Output:", Tb$, esi
Let esi=
Launch$("SlowPrint", SW_MINIMIZE, 1040)
PrintLine Str$("\nThird attempt, timeout=1040:
exit code=%i\n",
ExitCode(
$)), "Output:", Tb$, esi, CrLf$
Inkey "bye"
Exit
end start
Output:
## Launching SlowPrint.exe ##
First attempt, timeout=1000: exit code=259
Output: La$?
Second attempt, timeout=1020: exit code=0
Output: sp15 sp14 sp13 sp12 sp11 sp10 sp9 sp8 sp7 sp6 sp5 sp4 sp3 sp2 sp1 sp0 2656 ms
Third attempt, timeout=1040: exit code=0
Output: sp15 sp14 sp13 sp12 sp11 sp10 sp9 sp8 sp7 sp6 sp5 sp4 sp3 sp2 sp1 sp0 2656 ms