* [Caml-list] Pipes in 3.01
@ 2001-03-30 3:43 Laszlo Nemeth
0 siblings, 0 replies; 3+ messages in thread
From: Laszlo Nemeth @ 2001-03-30 3:43 UTC (permalink / raw)
To: caml-list
Hi,
I'm trying to implement an api for daVinci (my first ocaml program!)
and pipes don't seem to work:
module DaVinciAPI : DAVINCIAPI =
struct
exception DaVinciInitError
let daVinci () =
begin try
let (dIn, dOut) = Unix.pipe () in
let dProcess = Unix.create_process "daVinci"
[| "-pipe" |]
~stdin:dIn
~stdout:dOut
~stderr:Unix.stderr
and buf = String.create 100 in
let len = Unix.read dIn ~buf ~pos:0 100 in
if len > 0 then () else raise DaVinciInitError
with Unix.Unix_error _ -> raise DaVinciInitError
end;
The application starts up nicely, but I can't communicate with it. The
read blocks. On the other hand, if I start up daVinci in a shell (with
-pipe) it immediately sends back the string ok. I also tried to write
to the pipe, but to no avail (while doing the same from a shell works
perfectly).
Sorry for the probably trivial question but I haven't been able to
find (the new examples) examples of programming with pipes.
Any help, hints, pointers are appreciated.
Thanks, Laszlo
PS. I'm using the interactive environment (after linking in the unix
library) under Solaris.
-------------------
To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] Pipes in 3.01
2001-03-30 11:33 Damien Doligez
@ 2001-03-31 2:12 ` Laszlo Nemeth
0 siblings, 0 replies; 3+ messages in thread
From: Laszlo Nemeth @ 2001-03-31 2:12 UTC (permalink / raw)
To: Damien.Doligez; +Cc: caml-list
Thanks for all those (Damien, Francois, Fabrice) who replied and
pointed out my misunderstanding of IPC. Nevertheless, I did not manage
to make it work with 'create_process'. Instead, I started using
'open_process' which works wonderfully.
Thanks again. Laszlo
--- the working snippet:
module DaVinciAPI : DAVINCIAPI =
struct
exception DaVinciInitError
let daVinci () =
begin try
let (dIn, dOut) = Unix.open_process "daVinci -pipe"
and buf = String.create 10 in
let len = Unix.read (Unix.descr_of_in_channel dIn) ~buf ~pos:0 10
in
buf
with Unix.Unix_error _ -> raise DaVinciInitError
end
-------------------
To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] Pipes in 3.01
@ 2001-03-30 11:33 Damien Doligez
2001-03-31 2:12 ` Laszlo Nemeth
0 siblings, 1 reply; 3+ messages in thread
From: Damien Doligez @ 2001-03-30 11:33 UTC (permalink / raw)
To: caml-list, laszlo
>From: Laszlo Nemeth <laszlo@ropas.kaist.ac.kr>
> let (dIn, dOut) = Unix.pipe () in
You're creating one pipe.
> let dProcess = Unix.create_process "daVinci"
> [| "-pipe" |]
> ~stdin:dIn
> ~stdout:dOut
> ~stderr:Unix.stderr
You're piping the output of daVinci into its own input.
> let len = Unix.read dIn ~buf ~pos:0 100 in
You're competing with daVinci on reading its output
>On the other hand, if I start up daVinci in a shell (with
>-pipe) it immediately sends back the string ok.
I guess it does the same here, but it reads back the "ok" before you
do, then it waits for some more input.
If you want to send some input to daVinci AND get back its output, you
will need to create two pipes.
-- Damien
-------------------
To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2001-03-31 2:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-30 3:43 [Caml-list] Pipes in 3.01 Laszlo Nemeth
2001-03-30 11:33 Damien Doligez
2001-03-31 2:12 ` Laszlo Nemeth
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox