Skip to main content

ocaml pipe to a command

Context

As Linux system administrator I sometimes need to use pipes. A simple example:
 $ echo "some content text" | mail -s "this is" mihamina@rktmb.org 
I wondered how to do it with OCaml.

Pipe with Ocaml

What should be done:
  • Open the command as an output channel
  • Send what you want to that channel
How to:
 let buf = Unix.open_process_out "mail -s ddd mihamina@rktmb.org";; Pervasives.output_string buf "eeeeeeeeehol";; Pervasives.flush buf;; Unix.close_process_out buf;; 
And you're done!