Browse thread
[Caml-list] Ocaml equivalent of python's
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| 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 =
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