Consider b.nim:
    
    
    let x = stdin.readLine()
    echo("Got it: " & x)
    echo("#done")
    let y = stdin.readLine()
    echo("Got another one: " & y)
    echo("#done")
    
    
    Run

and a.nim:
    
    
    import osproc, streams
    from strutils import contains
    
    let p = startProcess("./b")
    
    proc read(ous: Stream) =
      var line: string
      while not line.contains("#done"):
        line = string(ous.readLine())
        echo "READ: " & line
    
    echo "MSG1"
    p.inputStream.writeLine("A")
    echo "Listening for MSG1 answer..."
    read(p.outputStream)
    echo "MSG2"
    p.inputStream.writeLine("B")
    echo "Listening for MSG2 answer..."
    read(p.outputStream)
    
    
    Run

The output stream(and the outputHandle) doesn't seem to work properly:

  * this won't be able to read even the first #done because the stream drops 
the output for some reason
  * in another try I was able to read the first message - because the other 
program started to respond much slower - but the got stuck again at the next
  * if I do it with a reader thread then it can print every line but it seems 
like the process is time-sensitive which means I can't use locks safely


Reply via email to