Run Piped External Commands using shexp

Task

Operating System / Run Piped External Commands

Opam Packages Used

  • shexp Tested with version: v0.16.0 — Used libraries: shexp, shexp.process

Code

The module Shexp_process.Infix contains the |- (pipe) operator.

open Shexp_process.Infix

We use the pipe operator and build a sequence of commands, then read_all to obtain its standard output.

let () =
  let sort_output =
    let open Shexp_process in
      eval (
        run "echo" ["t\nz\nu\na\nb"]
        |- run "sort" []
        |- read_all)
  in
  print_string sort_output

Recipe not working? Comments not clear or out of date?

Open an issue or contribute to this recipe!

Other Recipes for this Task