From: Xavier Leroy <xavier.leroy@inria.fr>
To: Johann Spies <jspies@sun.ac.za>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Ocaml equivalent of python's
Date: Wed, 6 Feb 2002 19:07:13 +0100 [thread overview]
Message-ID: <20020206190713.B9371@pauillac.inria.fr> (raw)
In-Reply-To: <20020206140335.GA27734@adept.co.za>; from jspies@sun.ac.za on Wed, Feb 06, 2002 at 04:03:35PM +0200
> 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
next prev parent reply other threads:[~2002-02-06 18:07 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-02-06 14:03 Johann Spies
2002-02-06 18:07 ` Xavier Leroy [this message]
2002-02-07 6:30 ` Johann Spies
2002-02-06 18:15 ` Remi VANICAT
2002-02-07 9:14 ` Nicolas barnier
2002-02-08 2:20 ` Julian Assange
2002-02-08 20:29 ` Chris Hecker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20020206190713.B9371@pauillac.inria.fr \
--to=xavier.leroy@inria.fr \
--cc=caml-list@inria.fr \
--cc=jspies@sun.ac.za \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox