Shexp is composed of two parts: a library providing a process monad for shell scripting in OCaml as well as a simple s-expression based shell interpreter. Shexp works on both Unix and Windows.
Shexp defines a few libraries that can be used independently.
Shexp_spawn is a small library exposing only one function:
Shexp_spawn.spawn
. Its purpose is to start command in the
background. Shexp_spawn aims to provide a few missing features of
Unix.create_process
such as providing a working directory as well as
improving errors reporting and performances.
Errors such as directory or program not found are properly reported as
Unix.Unix_error
exceptions, on both Unix and Windows.
On Unix, Shexp_spawn uses vfork
by default as it is often a lot
faster than fork. There is a benchmark comparing Shexp_spawn.spawn
to Unix.create_process
in spawn-lib/bench
. If you don’t trust
vfork
, you can set the environment variable SHEXP_USE_FORK
to make
Shexp_spawn use fork
instead.