create ~prog ~args ()
uses Core_unix.create_process_env
to create a child process that runs the executable prog
with args
as arguments.
This creates pipes to communicate with the child process's stdin
, stdout
, and stderr
. The caller is responsible for closing all these pipes. A lot of calls in the Reader
module will close the underlying fd (e.g. iterating on Reader.pipe
). You likely will have to explicitly call Writer.close
on the stdin
writer unless you call collect_output_and_wait
.
Unlike exec
, args
should not include prog
as the first argument.
If buf_len
is supplied, it determines the size of the reader and writer buffers used to communicate with the child process's stdin
, stdout
, and stderr
.
If stdin
is supplied, then the writer to the child's stdin will have ~raise_when_consumer_leaves:false
and ~buffer_age_limit:`Unlimited
, which makes it more robust.
env
specifies the environment of the child process.
If working_dir
is supplied, then the child process will chdir()
there before calling exec()
.
If argv0
is given, it is used (instead of prog
) as the first element of the argv
array passed to exec
.
create
returns Error
if it is unable to create the child process. This can happen in any number of situations (unable to fork, unable to create the pipes, unable to cd to working_dir
, unable to exec
etc.). create
does not return Error
if the binary exits with non-zero exit code; instead, it returns OK t
, where wait t
returns an Error
.
See Core_unix.create_process_env
for more details.