Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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 <> 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:  FAQ:
To unsubscribe, mail  Archives: