Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Creating a pipeline under windows
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-04-15 (04:20)
From: jamesj@g...
Subject: Creating a pipeline under windows
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