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 FAA25807; Thu, 13 Nov 2003 05:09:18 +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 FAA25434 for ; Thu, 13 Nov 2003 05:09:14 +0100 (MET) Received: from bob.west.spy.net (mail.west.spy.net [66.149.231.226]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id hAD49A106820 for ; Thu, 13 Nov 2003 05:09:13 +0100 (MET) Received: from [192.168.1.50] (dustinti.west.spy.net [192.168.1.50]) by bob.west.spy.net (Postfix) with ESMTP id 0013367CD; Wed, 12 Nov 2003 20:09:06 -0800 (PST) In-Reply-To: <3FB2DBEB.40806@lindows.com> References: <6CF992BC-1573-11D8-A660-000393CFE6B8@spy.net> <3FB2DBEB.40806@lindows.com> Mime-Version: 1.0 (Apple Message framework v606) Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: <1F8BACD0-158F-11D8-982B-000393CB0F1E@spy.net> Content-Transfer-Encoding: 7bit Cc: Caml Mailing List From: Dustin Sallings Subject: Re: [Caml-list] GC and file descriptors Date: Wed, 12 Nov 2003 20:09:06 -0800 To: David Fox X-Mailer: Apple Mail (2.606) X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 wexited:01 bourne:01 subprocesses:01 cae:99 garbage:01 descriptors:01 descriptors:01 command:98 command:98 buf:01 buf:01 nov:01 match:02 her:97 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > Dustin Sallings wrote: > >> >> I keep ending up with somewhat awkward structures to close files >> I've opened. Does the GC take care of any of this type of thing? On Nov 12, 2003, at 17:18, David Fox wrote: > I might start with this > > let for_process_output f cmd = > let r = Unix.open_process_in cmd in > let result = f r in > Unix.close_process_in r; > result > > then > > let tput x = for_process_output (fun r -> input r buf 0 8) ("tput " ^ > x) > > at which point you start thinking about exception handling... Well, I didn't see the close_process thing, but that made things a bit worse. My goal is to capture the output of a command with each of two args. I currently have this: exception SubprocessError of string;; (* Get a string from the tput command. *) let tput x = let r = Unix.open_process_in ("tput " ^ x) and buf = String.create 8 in let len = input r buf 0 8 in let status = Unix.close_process_in r in begin match status with Unix.WEXITED(st) -> if (st != 0) then raise (SubprocessError "Non-zero exit status"); | _ -> raise (SubprocessError "Unknown error."); end; String.sub buf 0 len ;; (* The two characters we need. *) let smso = tput "smso";; let rmso = tput "rmso";; This is to give me the equivalent of the following bourne shell: smso=`tput smso` rmso=`tput rmso` Garbage collecting the subprocesses and file descriptors would make this a bit more straightforward. -- SPY My girlfriend asked me which one I like better. pub 1024/3CAE01D5 1994/11/03 Dustin Sallings | Key fingerprint = 87 02 57 08 02 D0 DA D6 C8 0F 3E 65 51 98 D8 BE L_______________________ I hope the answer won't upset her. ____________ ------------------- 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