You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I'm trying to write an app that could start a subprocess, and react to its stdout or stderr, depending on what shows up. I was given some initial advice on Nim forum, and I tried to build something based on it, but I think I must be doing something wrong, as I'm not getting results I was expecting :( I have files like below:
q_async.nim
import asynctools/[asyncproc, asyncpipe]
import asyncfutures
import asyncdispatch
var p =startProcess("q_outerr", options = {})
var pout = p.outputHandle
var perr = p.errorHandle
procnext() {.async.} =var bufo =newString(1)
var fo = pout.readInto(bufo[0].addr, bufo.len)
var bufe =newString(1)
var fe = perr.readInto(bufe[0].addr, bufe.len)
var fx = p.waitForExit()
whiletrue:
await fe or fo or fx
if fo.finished:
if fo.read >0:
echo"O ", fo.read(), "", bufo.substr(0, fo.read()-1)
fo = pout.readInto(bufo[0].addr, bufo.len)
if fe.finished:
if fe.read >0:
echo"E ", fe.read(), "", bufe.substr(0, fe.read()-1)
fe = perr.readInto(bufe[0].addr, bufe.len)
if fx.finished:
echo"X ", fx.read()
returnif fo.finished and fe.finished and fo.read==0and fe.read==0:
returnwaitFornext()
Hi, I'm trying to write an app that could start a subprocess, and react to its stdout or stderr, depending on what shows up. I was given some initial advice on Nim forum, and I tried to build something based on it, but I think I must be doing something wrong, as I'm not getting results I was expecting :( I have files like below:
q_async.nim
q_outerr.nim
Results
Now, when I compile both, and run
q_async.exe
(on Windows), I'm getting output like below:If I remove
fx
fromq_async
, it's just hanging at some point, still not printing all output fromq_outerr
.Do you have any idea what I might be doing wrong, and how I could make this work correctly, to display all stdout & stderr from
q_outerr.nim
?The text was updated successfully, but these errors were encountered: