* [Caml-list] Unix.open_process "cat"
@ 2004-05-15 11:13 Martin Jambon
2004-05-15 16:21 ` Olivier Andrieu
0 siblings, 1 reply; 2+ messages in thread
From: Martin Jambon @ 2004-05-15 11:13 UTC (permalink / raw)
To: caml-list
Hello,
I would like to apply some external filters (e.g. cat, grep, sed, ...)
that will terminate successfully only if they reach an
end-of-file. For this I would like to use Unix.open_process, but I need to
close the output first (= the input of the command).
Is it legal to use close_out on the out_channel returned by
Unix.open_process, and later use Unix.close_process on the pair of
channels?
Here is my code (which seems to work):
#load "unix.cma"
let feed command data f =
let (ic, oc) as channels = Unix.open_process command in
output_string oc data;
close_out oc; (** <-- is this OK? **)
(try
while true do
f (input_char ic)
done
with End_of_file -> ());
match Unix.close_process channels with
Unix.WEXITED 0 -> ()
| _ -> invalid_arg ("feed: " ^ command)
let _ = feed "cat" "mouse" print_char
Martin
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] Unix.open_process "cat"
2004-05-15 11:13 [Caml-list] Unix.open_process "cat" Martin Jambon
@ 2004-05-15 16:21 ` Olivier Andrieu
0 siblings, 0 replies; 2+ messages in thread
From: Olivier Andrieu @ 2004-05-15 16:21 UTC (permalink / raw)
To: martin_jambon; +Cc: caml-list
Martin Jambon [Sat, 15 May 2004]:
> Hello,
>
> I would like to apply some external filters (e.g. cat, grep, sed, ...)
> that will terminate successfully only if they reach an
> end-of-file. For this I would like to use Unix.open_process, but I need to
> close the output first (= the input of the command).
> Is it legal to use close_out on the out_channel returned by
> Unix.open_process, and later use Unix.close_process on the pair of
> channels?
Yes, Unix.close_process will call close_out on the channel again but
this is safe.
--
Olivier
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-05-15 17:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-15 11:13 [Caml-list] Unix.open_process "cat" Martin Jambon
2004-05-15 16:21 ` Olivier Andrieu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox