# Using Ocaml as scripting language - piping sh commands

**URL:** <https://discuss.ocaml.org/t/using-ocaml-as-scripting-language-piping-sh-commands/5366>\
**Category:** Learning\
**Created:** [March 23, 2020, 10:10am UTC](https://discuss.ocaml.org/t/using-ocaml-as-scripting-language-piping-sh-commands/5366 "2020-03-23T10:10:08Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![nico\_toll](https://avatars.discourse-cdn.com/v4/letter/n/22d042/32.png) [@nico\_toll](https://discuss.ocaml.org/u/nico_toll)\
**Post date:** [March 23, 2020, 10:10am UTC](https://discuss.ocaml.org/t/using-ocaml-as-scripting-language-piping-sh-commands/5366/1 "2020-03-23T10:10:08Z")

</div>

I am trying to use ocaml to pipe the result of a command to another (I would also be interested in feeding a string or a io stream into a sh command). For example, I would like to do the equivalent of cat foo.txt | grep thing, or pipe the result of one of my ocaml function into grep.

Quite surprinsingly, neither the Stdlib or Batteries Sys modules expose any way to handle the output of Sys.command directly (I would have thought there would be optional input and output arguments defaulting to stdin and stdout, or something along that). Batteries IO module does expose a pipe function but it’s not clear for me how it would interact with the Sys module. Any ideas or other modules/package I could use ?

Thanks

---

_[View the full topic](https://discuss.ocaml.org/t/using-ocaml-as-scripting-language-piping-sh-commands/5366)._
