New sample:

a.nim:
    
    
    import osproc, streams, threadpool
    from strutils import contains
    from os import sleep
    
    let p = startProcess("./b")
    var channel: Channel[seq[string]]
    open(channel)
    
    proc listen(ous: Stream) {.thread.} =
       while true:
         var buffer: seq[string]
         var line: string
         while not line.contains("#done"):
           line = ous.readLine()
           echo "READ: " & line
           buffer.add(line)
         channel.send(buffer)
    
    proc getOrWait() =
      while true:
        let (received, msg) = tryRecv(channel)
        if received:
          echo $msg
          break
        sleep(10)
    
    spawn listen(p.outputStream)
    
    echo "MSG1"
    p.inputStream.writeLine("A")
    echo "Listening for MSG1 answer..."
    getOrWait()
    echo "MSG2"
    p.inputStream.writeLine("B")
    echo "Listening for MSG2 answer..."
    getOrWait()
    
    
    Run

b.nim:
    
    
    from os import sleep
    
    #SECTION A
    sleep(100)
    echo("AAA")
    sleep(100)
    echo("BBB")
    sleep(100)
    echo("CCC")
    sleep(100)
    #/SECTION A
    
    let x = stdin.readLine()
    writeFile("l.log", x)
    sleep(100)
    echo("Got it: " & x)
    sleep(100)
    echo("#done")
    sleep(100)
    
    let y = stdin.readLine()
    echo("Got another one: " & y)
    echo("#done")
    
    
    Run

Even if I delete SECTION A the l.log file won't exist - which probably means 
that startProcess's input doesn't even work.

Reply via email to