Module Spawn
Mini spawn library
module Working_dir : sig ... end
module Unix_backend : sig ... end
module Env : sig ... end
val spawn : ?env:Env.t -> ?cwd:Working_dir.t -> prog:string -> argv:string list -> ?stdin:Unix.file_descr -> ?stdout:Unix.file_descr -> ?stderr:Unix.file_descr -> ?unix_backend:Unix_backend.t -> unit -> int
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 inPATH
. 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.Note that when
prog
is a relative filename, it is interpreted as a path relative to the working directory specified by thecwd
argument. On Windows, this differs from what the underlyingCreateProcess
function does.Command line arguments
argv
is the full command line. The first element should be the program name and subsequent elements the command line arguments. Note that the head ofargv
doesn't necessarily have to be equal toprog
. For instance it might befoo
whileprog
might be/usr/bin/foo
.Environment
env
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 toInherit
. It is an error to passFd _
on Windows.Standard input/outputs
stdin
,stdout
andstderr
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 toDefault
,vfork
is used unless the environment variableSPAWN_USE_FORK
is set. On Windows,CreateProcess
is used.