I am trying to write a cross-platform program that will simulate the effect of the following shell command:
prog1 | prog2
i.e. create a pipeline. The following code
let () =
let r,w = Unix.pipe () in
Unix.set_close_on_exec w;
let w_pid = Unix.create_process "prog2" [|"prog2"|] r Unix.stdout Unix.stderr in
Unix.close r;
let r_pid = Unix.create_process "prog1" [|"prog1"|] Unix.stdin w Unix.stderr in
Unix.close w;
assert (snd (Unix.waitpid [] w_pid) = Unix.WEXITED 0 &&
snd (Unix.waitpid [] r_pid) = Unix.WEXITED 0)
works fine on linux but not on windows (using the native port). I tried to comment out the Unix.set_close_on_exec and/or the Unix.close lines but it does not help. I was not successful with the Unix.open_process_* functions either.