From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA15463; Fri, 15 Feb 2002 17:07:53 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA15665 for ; Fri, 15 Feb 2002 17:07:52 +0100 (MET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g1FG7m521918; Fri, 15 Feb 2002 17:07:48 +0100 (MET) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA11714; Fri, 15 Feb 2002 17:07:48 +0100 (MET) Date: Fri, 15 Feb 2002 17:07:48 +0100 From: Xavier Leroy To: David Fox Cc: caml-list@inria.fr Subject: Re: [Caml-list] process conundrum Message-ID: <20020215170748.C14578@pauillac.inria.fr> References: <87adudcb2l.fsf@foxthompson.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <87adudcb2l.fsf@foxthompson.net>; from david@lindows.com on Wed, Feb 13, 2002 at 01:43:14PM -0800 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > Suppose I open a process to reverse the lines of a file like so: > > # let readable, writable = > Unix.open_process "cat -n | sort -n -r | sed 's:^[ 0-9]*[^ 0-9]::'";; > > Then I write a few lines to it: > Now I close the write end to cause an EOF, so the output arrives on readable: > How do I cleanly terminate the process? > # Unix.close_process (readable, writable);; > Exception: Sys_error "Bad file descriptor". This is indeed a bug in Unix.close_process: when it closes both channels, it should not fail if the output channel is already closed. Notice however a potential problem in your code: Unix pipes are fixed-size buffers, so if you write a lot of data to one pipe, the output pipe may fill up and the underlying process will block. Thus, Unix.open_process is usable only if you can alternate writes (of small quantities) and reads, e.g. via two threads. In other cases, it is necessary to use an intermediate file, to hold either the input or the output of the command. - Xavier Leroy ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr