Version française
Home     About     Download     Resources     Contact us    
Browse thread
Unix.create_process vs Unix.open_process_out
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Johann Spies <jspies@s...>
Subject: Re: [Caml-list] Unix.create_process vs Unix.open_process_out
On Mon, Apr 14, 2008 at 08:43:14AM -0400, James Jones wrote:
> Consider the following two functions:
> 
> let test1 () =
>   let w = Unix.open_process_out "cat" in
>   assert (Unix.close_process_out w = Unix.WEXITED 0)
> 
> let test2 () =
>   let r,w = Unix.pipe () in
>   let pid = Unix.create_process "cat" [| "cat" |] r Unix.stdout Unix.stderr in
>   Unix.close w;
>   assert (snd (Unix.waitpid [] pid) = Unix.WEXITED 0)
> 
> 
> Both execute "cat" and then close its stdin immediately. This should cause cat
> to terminate. In test1 this works as expected but in test2, cat keeps running
> forever. Is this the expected behavior of Unix.create_process?

Did you try "cat <file>" ?

If you just type 'cat' on the commandline it waits for input on
stdin.  If you 'cat <file>' it finishes the job and exit.

Regards
Johann
--
Johann Spies          Telefoon: 021-808 4036
Informasietegnologie, Universiteit van Stellenbosch

     "For the word of God is quick, and powerful, and  
      sharper than any twoedged sword, piercing even to  
      the dividing asunder of soul and spirit, and of the
      joints and marrow, and is a discerner of the thoughts
      and intents of the heart."      Hebrews 4:12