English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] Ocaml equivalent of python's
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-02-06 (18:15)
From: Remi VANICAT <vanicat@l...>
Subject: Re: [Caml-list] Ocaml equivalent of python's
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 =
    let line = input_line file in in
    line :: (list_of_line file_in)
    | 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
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