caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Unix.create_process
@ 2001-12-19 16:34 Rolf Wester
  2001-12-20 15:14 ` Francois Pottier
  0 siblings, 1 reply; 2+ messages in thread
From: Rolf Wester @ 2001-12-19 16:34 UTC (permalink / raw)
  To: caml-list

Hi,

I want to start a process and read the stdout channel of this process.
I tried:

let instring = String.create 10 in
    let pid = Unix.create_process ~prog:"ls" ~args:[|"/usr"|] 
			~stdin:Unix.stdin ~stdout:Unix.stdin ~stderr:Unix.stderr in
    let nread = Unix.read Unix.stdin ~buf:instring ~pos:0 ~len:10 in instring;;

but this one waits for keyboeard input instead of reading the output of ls.
When I type  ~stdout:Unix.stdout instead of  ~stdout:Unix.stdin the ls 
output is written to stdout (as expected).

Can anybody tell me what I made wrong?

Thanks in advance.

Rofl Wester 

-------------------------------------
Rolf Wester
rolf.wester@ilt.fraunhofer.de
-------------------
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] 2+ messages in thread

* Re: [Caml-list] Unix.create_process
  2001-12-19 16:34 [Caml-list] Unix.create_process Rolf Wester
@ 2001-12-20 15:14 ` Francois Pottier
  0 siblings, 0 replies; 2+ messages in thread
From: Francois Pottier @ 2001-12-20 15:14 UTC (permalink / raw)
  To: caml-list


Hi Rolf,

You need to create a pipe, have the process write into one end of it, and read
data off the other end. The function [Unix.open_process_in] does that for
you. Here is an example:

  let one_liner command =
    let channel = Unix.open_process_in command in
    let line = input_line channel in
    let _ = Unix.close_process_in channel in
    line
  ;;

-- 
François Pottier
Francois.Pottier@inria.fr
http://pauillac.inria.fr/~fpottier/
-------------------
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] 2+ messages in thread

end of thread, other threads:[~2001-12-20 15:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-19 16:34 [Caml-list] Unix.create_process Rolf Wester
2001-12-20 15:14 ` Francois Pottier

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