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 TAA10024; Wed, 6 Feb 2002 19:07:21 +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 TAA11167 for ; Wed, 6 Feb 2002 19:07:20 +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 g16I7En14828; Wed, 6 Feb 2002 19:07:14 +0100 (MET) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA10675; Wed, 6 Feb 2002 19:07:13 +0100 (MET) Date: Wed, 6 Feb 2002 19:07:13 +0100 From: Xavier Leroy To: Johann Spies Cc: caml-list@inria.fr Subject: Re: [Caml-list] Ocaml equivalent of python's Message-ID: <20020206190713.B9371@pauillac.inria.fr> References: <20020206140335.GA27734@adept.co.za> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <20020206140335.GA27734@adept.co.za>; from jspies@sun.ac.za on Wed, Feb 06, 2002 at 04:03:35PM +0200 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > I want to learn how to use Unix commands from within an Ocaml program > but the Ocaml manual confused me more than it helped me to understand > the Ocaml way. > > In Python I can do the following; > ------------------------------ > import commands, os > > listing = os.system ('ls -laprt') #or any other unix command > > print listing # to get the output of the unix command. > > address = 146.232.128.13 > result = commands.getstatusoutput('ping -c 1 %s' % address,) > > print result > ----------------------------------- > What would the equivalent be in Ocaml? I don't know Python, so I can only guess at what you're trying to do. But here is a sketch: let ping_address addr = Sys.command("ping -c 1 " ^ address) This function runs "ping" and returns it return code, as an integer. For your first example: let ic = Unix.open_process_in("ls -laprt") in (* read from the input channel ic with input_char, input_line, input, etc. When finished: *) Unix.close_process_in ic Hope this helps, - 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