Streaming output from a program with Eio

Hey

I’m trying to understand if this is possible.

I’d like to open a new unix process, and stream the output using Seq, but I can’t really figure out the correct incantation.

This is what I’ve tried so far

Eio_main.run @@ fun env ->
  let proc_mgr = Eio.Stdenv.process_mgr env in
  let output = Eio.Process.parse_out proc_mgr Eio.Buf_read.lines ["cat"]
    ~stdin:(Eio.Flow.string_source "One two three\nOne two three\n")
   in
  output |> Seq.iter (fun line -> Eio.traceln "%S" line);; 

and the error I’m getting is


Exception: Failure “Unexpected data after parsing (at offset 0)”.
Raised at Stdlib.failwith in file “stdlib.ml”, line 29, characters 17-33

You need to read the lines during parsing, not after the Eio.Process.parse_out is finished (and the process is gone).

The example with Buf_read.seq might help.

1 Like