Run an External Command and Process Stdout using shexp
Task
Operating System / Run an External Command and Process Stdout
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 to build a sequence consisting of the single command
ps -x
, then read_all
to obtain its standard output.
let () =
let ps_output =
let open Shexp_process in
eval (run "ps" ["-x"] |- read_all)
in
print_endline ps_output