caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Ocaml equivalent of python's
@ 2002-02-06 14:03 Johann Spies
  2002-02-06 18:07 ` Xavier Leroy
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Johann Spies @ 2002-02-06 14:03 UTC (permalink / raw)
  To: caml-list

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 have tried 
-------------------------------------------------
#  let listing = Unix.execv "ls -laprt";;
val listing : string array -> unit = <fun>
# let l = Array.to_list listing;;
This expression has type string array -> unit but is here used with
type
  'a array
-------------------------------------------------


Johann
-- 
Johann Spies          Telefoon: 021-808 4036
Informasietegnologie, Universiteit van Stellenbosch

     "He hath not dealt with us after our sins; nor rewarded
      us according to our iniquities. For as the heaven is 
      high above the earth, so great is his mercy toward 
      them that fear him. As far as the east is from the 
      west, so far hath he removed our transgressions from 
      us."                  Psalms 103:10-12 
-------------------
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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Ocaml equivalent of python's
  2002-02-06 14:03 [Caml-list] Ocaml equivalent of python's Johann Spies
@ 2002-02-06 18:07 ` Xavier Leroy
  2002-02-07  6:30   ` Johann Spies
  2002-02-06 18:15 ` Remi VANICAT
  2002-02-07  9:14 ` Nicolas barnier
  2 siblings, 1 reply; 7+ messages in thread
From: Xavier Leroy @ 2002-02-06 18:07 UTC (permalink / raw)
  To: Johann Spies; +Cc: caml-list

> 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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Ocaml equivalent of python's
  2002-02-06 14:03 [Caml-list] Ocaml equivalent of python's Johann Spies
  2002-02-06 18:07 ` Xavier Leroy
@ 2002-02-06 18:15 ` Remi VANICAT
  2002-02-07  9:14 ` Nicolas barnier
  2 siblings, 0 replies; 7+ messages in thread
From: Remi VANICAT @ 2002-02-06 18:15 UTC (permalink / raw)
  To: caml-list

Johann Spies <jspies@sun.ac.za> writes:

> I have tried 
> -------------------------------------------------
> #  let listing = Unix.execv "ls -laprt";;
> val listing : string array -> unit = <fun>
> # let l = Array.to_list listing;;
> This expression has type string array -> unit but is here used with
> type
>   'a array
> -------------------------------------------------

Unix.execv is a raw interface to the exec unix system call.

You should use the "High-level process and redirection management"
function :

let reading = open_process_in "ls -laprt";;

then reading is a in_channel that you can read with the General input
functions of the core library.

for example if you want the list of the line :

let rec list_of_line file_in =
  try
    let line = input_line file in in
    line :: (list_of_line file_in)
  with    
    | End_of_file -> []

but stream may be more useful than list to manipulate information
from a channel
(and the Directories function of the Unix library are more useful
than this list, if you want to know what is in a directory)
-- 
Rémi Vanicat
vanicat@labri.u-bordeaux.fr
http://dept-info.labri.u-bordeaux.fr/~vanicat
-------------------
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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Ocaml equivalent of python's
  2002-02-06 18:07 ` Xavier Leroy
@ 2002-02-07  6:30   ` Johann Spies
  0 siblings, 0 replies; 7+ messages in thread
From: Johann Spies @ 2002-02-07  6:30 UTC (permalink / raw)
  To: caml-list

Thank you Xavier and Remi for your answers.  Examples like that in the
Ocaml Manual would make things much easier for newbies.

Regards.
Johann
-- 
Johann Spies          Telefoon: 021-808 4036
Informasietegnologie, Universiteit van Stellenbosch

     "But the LORD is in his holy temple; let all the earth 
      keep silence before him."           Habakkuk 2:20 
-------------------
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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Ocaml equivalent of python's
  2002-02-06 14:03 [Caml-list] Ocaml equivalent of python's Johann Spies
  2002-02-06 18:07 ` Xavier Leroy
  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
  2 siblings, 2 replies; 7+ messages in thread
From: Nicolas barnier @ 2002-02-07  9:14 UTC (permalink / raw)
  To: Johann Spies, ocaml

Hello Johann,

I find offensive that you take advantage of the Caml list,
a purely computer science list, to proselytize. Could you
please stop appending such (long) signature to your mails ?
It surely is not worth the bandwidth.

-- Nicolas

Johann Spies wrote:
> --
> Johann Spies          Telefoon: 021-808 4036
> Informasietegnologie, Universiteit van Stellenbosch
> 
>      "He hath not dealt with us after our sins; nor rewarded
>       us according to our iniquities. For as the heaven is
>       high above the earth, so great is his mercy toward
>       them that fear him. As far as the east is from the
>       west, so far hath he removed our transgressions from
>       us."                  Psalms 103:10-12
-------------------
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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Ocaml equivalent of python's
  2002-02-07  9:14 ` Nicolas barnier
@ 2002-02-08  2:20   ` Julian Assange
  2002-02-08 20:29   ` Chris Hecker
  1 sibling, 0 replies; 7+ messages in thread
From: Julian Assange @ 2002-02-08  2:20 UTC (permalink / raw)
  To: Nicolas barnier; +Cc: Johann Spies, ocaml

Although I strongly disagree with the content, I do find these
signatures offensive. People must not only be allowed to be different
but they must be allowed to be seen to be different.

A community of people behaving identically or worse actually containing
no difference, is not one I wish to be part of.

--
 Julian Assange        |If you want to build a ship, don't drum up people
                       |together to collect wood or assign them tasks and
 proff@iq.org          |work, but rather teach them to long for the endless
 proff@gnu.ai.mit.edu  |immensity of the sea. -- Antoine de Saint Exupery
-------------------
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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Ocaml equivalent of python's
  2002-02-07  9:14 ` Nicolas barnier
  2002-02-08  2:20   ` Julian Assange
@ 2002-02-08 20:29   ` Chris Hecker
  1 sibling, 0 replies; 7+ messages in thread
From: Chris Hecker @ 2002-02-08 20:29 UTC (permalink / raw)
  To: Nicolas barnier, Johann Spies, ocaml


>I find offensive that you take advantage of the Caml list,
>a purely computer science list, to proselytize. Could you
>please stop appending such (long) signature to your mails ?
>It surely is not worth the bandwidth.

What's a waste of bandwidth is you taking issue with it and starting this thread.  The signature you quoted was 348 bytes.  Your reply, not counting headers, was 1147 bytes, and if you count my reply and Julian's jumping to his defense publicly, which is somewhat necessary in these situations, it was 2813 or so.

I'm about the most athiestic person I know, but commenting on somebody's signature is pretty lame.

It was 6 lines, and he usually uses only 2 lines.  Who cares?  Leave him alone.

Chris


-------------------
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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2002-02-08 20:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-06 14:03 [Caml-list] Ocaml equivalent of python's Johann Spies
2002-02-06 18:07 ` Xavier Leroy
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).