Read output only while input is not asked

2022-03-23 Thread demotomohiro
When `readLineTimeout` got timeout as it read output from `b.nim` and `b.nim` called `stdin.readLine`, `readStream.readLine` thread you spawned keep alive even when `readLineTimeout` returned and it can read output from `b.nim`. I that case, output read by that `readStream.readLine` call is not

Read output only while input is not asked

2022-03-22 Thread Limits
I've found a way to do it using timeouts a.nim: import std/osproc, std/streams, std/times, std/threadpool, std/os proc readLineTimeout(readStream: Stream, timeout: float): int = var FlowVar = spawn readStream.readLine t = cpuTime() while cpuTime()

Read output only while input is not asked

2022-03-21 Thread demotomohiro
Both `readXYZ` and `peekXYZ` procs in stream module block until it get enough data to return. `stdin.readLine` in your b.nim blocks your code until it get a line. You can read all lines from b.nim and write stdin for b.nim if you know many lines b.nim writes: a1.nim: import std/[

Read output only while input is not asked

2022-03-21 Thread ynfle
Your issue is that b is waiting to receive input and you are waiting to read a line until the stream closes. Try

Read output only while input is not asked

2022-03-21 Thread hamidrb80
I guess you should use Stream thingy in `a.nim`. take a look at:

Read output only while input is not asked

2022-03-19 Thread Limits
`a.nim`: import std/osproc, std/streams let myprocess = startProcess("./b") var i = 0 while true: var s: string = "" while myprocess.outputstream.readLine(s): echo s echo i i += 1 myprocess.inputstream.write($i) Run