From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id EE2ACBC69 for ; Wed, 22 Aug 2007 22:05:44 +0200 (CEST) Received: from comtv.ru (comtv.ru [217.10.32.17]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l7MK5i3W020302 for ; Wed, 22 Aug 2007 22:05:44 +0200 X-UCL: actv Received: from av1474.oops ([10.0.66.9] verified) by comtv.ru (CommuniGate Pro SMTP 4.1.8) with ESMTP-TLS id 76512723; Thu, 23 Aug 2007 00:05:43 +0400 Date: Thu, 23 Aug 2007 00:05:22 +0400 (MSD) From: malc X-X-Sender: malc@linmac.oyster.ru To: Luca de Alfaro Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] commands.getoutput () in ocaml? In-Reply-To: <28fa90930708221256t497e8356k84861abd6b2e91b8@mail.gmail.com> Message-ID: References: <28fa90930708221256t497e8356k84861abd6b2e91b8@mail.gmail.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Miltered: at discorde with ID 46CC9718.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; malc:01 ocaml:01 ocaml:01 succint:01 buffer:01 buffer:01 2007,:98 vale:98 wrote:01 wrote:01 unix:01 unix:01 rec:01 caml-list:01 match:02 On Wed, 22 Aug 2007, Luca de Alfaro wrote: > Dear All, > > I am looking for a quick way to do the equivalent of > > s = commands.getoutput ("ls " + name + "*") > > in Ocaml. > > Unix.system does perform a call, but the output of the call is not > returned... yes, I can redirect it to /tmp/output.ocaml and then read the > file, or even go crazy and build pipes, but is there a more elegant (read: > succint) way to do it? I needed something to that effect yesterday and wrote following: open Unix;; let getprocout cmd = let ic = open_process_in cmd in let b = Buffer.create 10 in let rec loop () = match try Some (input_line ic) with End_of_file -> None with | None -> Buffer.contents b | Some line -> Buffer.add_string b line; loop () in loop () ;; -- vale