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 NAA17194; Sat, 15 May 2004 13:13:35 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id NAA17414 for ; Sat, 15 May 2004 13:13:33 +0200 (MET DST) Received: from out2.smtp.messagingengine.com (out2.smtp.messagingengine.com [66.111.4.26]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i4FBDWEV024109 for ; Sat, 15 May 2004 13:13:33 +0200 X-Sasl-enc: PoR2MTaywR3hU660+j7gIg 1084619611 Received: from [192.168.1.100] (unknown [218.81.120.34]) by mail.messagingengine.com (Postfix) with ESMTP id A42DFB82ED6 for ; Sat, 15 May 2004 07:13:30 -0400 (EDT) Date: Sat, 15 May 2004 19:13:20 +0800 (HKT) From: Martin Jambon X-X-Sender: martin@localhost To: caml-list@inria.fr Subject: [Caml-list] Unix.open_process "cat" Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Miltered: at nez-perce with ID 40A5FB5C.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; char:01 wexited:01 char:01 command:98 command:98 match:02 unix:02 unix:02 jambon:02 jambon:02 external:03 string:03 cma:03 sed:03 data:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hello, I would like to apply some external filters (e.g. cat, grep, sed, ...) that will terminate successfully only if they reach an end-of-file. For this I would like to use Unix.open_process, but I need to close the output first (= the input of the command). Is it legal to use close_out on the out_channel returned by Unix.open_process, and later use Unix.close_process on the pair of channels? Here is my code (which seems to work): #load "unix.cma" let feed command data f = let (ic, oc) as channels = Unix.open_process command in output_string oc data; close_out oc; (** <-- is this OK? **) (try while true do f (input_char ic) done with End_of_file -> ()); match Unix.close_process channels with Unix.WEXITED 0 -> () | _ -> invalid_arg ("feed: " ^ command) let _ = feed "cat" "mouse" print_char Martin ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners