Spawn a sub-command and return its PID. This function is low-level and should be used to build higher-level APIs.
In case of errors, it raises Unix.Unix_error
.
Binary
prog
is not searched in PATH
. It is up to the caller to do the path resolution before calling this function. Note that there is no special treatment of executable text files without a proper #!. The execvp function from the C library calls /bin/sh
in this case to imitate the behaviors of a shell but this function doesn't.
Environment
env
must be a list of strings of the form "KEY=VALUE"
. It represents the environment in which the sub-process is executed. If not specified, the environment from the process calling this function is used.
Working directory
cwd
describes what the current working directory of the sub-process should be. It defaults to Inherit
. It is an error to pass Fd _
on Windows.
Standard input/outputs
stdin
, stdout
and stderr
are the file descriptors used as standard input, output and error output of the sub-process. When not specified, they default to the ones from the calling process.
Signals
On Unix, the sub-process will have all its signals unblocked.
Implementation
unix_backend
describes what backend to use on Unix. If set to Default
, vfork
is used unless the environment variable SPAWN_USE_FORK
is set. On Windows, CreateProcess
is used.