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 CAA20691; Thu, 13 Nov 2003 02:18:39 +0100 (MET) 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 CAA20507 for ; Thu, 13 Nov 2003 02:18:38 +0100 (MET) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from mail.lindows.com ([130.94.123.204]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id hAD1Ib129694 for ; Thu, 13 Nov 2003 02:18:37 +0100 (MET) Received: from lindows.com (adsl-63-196-84-93.dsl.sndg02.pacbell.net [63.196.84.93]) by mail.lindows.com (Postfix) with ESMTP id 057737235E; Wed, 12 Nov 2003 17:17:09 -0800 (PST) Message-ID: <3FB2DBEB.40806@lindows.com> Date: Wed, 12 Nov 2003 17:18:35 -0800 From: David Fox User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031107 Debian/1.5-2.0.0.lindows0.0.17.45+0 X-Accept-Language: en MIME-Version: 1.0 To: Dustin Sallings Cc: Caml Mailing List Subject: Re: [Caml-list] GC and file descriptors References: <6CF992BC-1573-11D8-A660-000393CFE6B8@spy.net> In-Reply-To: <6CF992BC-1573-11D8-A660-000393CFE6B8@spy.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Loop: caml-list@inria.fr X-Spam: no; 0.00; lindows:01 caml-list:01 descriptors:01 buf:01 buf:01 exception:02 unix:02 unix:02 string:03 string:03 wrote:03 let:04 let:04 fox:04 fox:04 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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... 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? > > I.e., could the following: > > 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 > close_in r; > String.sub buf 0 len > ;; > > be written like this: > > let tput x = > let buf = String.create 8 in > String.sub buf 0 (input (Unix.open_process_in ("tput " ^ x)) buf 0 8) > ;; > > safely? > ------------------- 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