Module Async_unix__.Process
val sexp_of_t : t -> Ppx_sexp_conv_lib.Sexp.t
val pid : t -> Core.Pid.t
val stdin : t -> Async_unix.Writer.t
val stdout : t -> Async_unix.Reader.t
val stderr : t -> Async_unix.Reader.t
type env
= Core.Unix.env
val sexp_of_env : env -> Ppx_sexp_conv_lib.Sexp.t
val env_of_sexp : Ppx_sexp_conv_lib.Sexp.t -> env
type 'a create
= ?argv0:string -> ?buf_len:int -> ?env:env -> ?prog_search_path:string list -> ?stdin:string -> ?working_dir:string -> prog:string -> args:string list -> unit -> 'a Async_unix__.Import.Deferred.t
create ~prog ~args ()
usesCore.Unix.create_process_env
to create a child process that runs the executableprog
withargs
as arguments. It creates pipes to communicate with the child process'sstdin
,stdout
, andstderr
.Unlike
exec
,args
should not includeprog
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'sstdin
,stdout
, andstderr
.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 willchdir()
there before callingexec()
.If
argv0
is given, it is used (instead ofprog
) as the first element of theargv
array passed toexec
.create
returnsError
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 toworking_dir
, unable toexec
etc.).create
does not returnError
if the binary exits with non-zero exit code; instead, it returnsOK t
, wherewait t
returns anError
.See
Core.Unix.create_process_env
for more details.
val create : t Core.Or_error.t create
val create_exn : t create
val wait : t -> Core.Unix.Exit_or_signal.t Async_unix__.Import.Deferred.t
wait t = Unix.waitpid (pid t)
.wait
's result becomes determined when the child process terminates, via exit or signal.wait
does not touchstdin
,stdout
orstderr
. The caller should ensure thatstdout
andstderr
are being drained in the background to avoid the child process blocking on a write due to pushback. Seecollect_output_and_wait
for a higher-level alternative that handles this.
module Output : sig ... end
val collect_output_and_wait : t -> Output.t Async_unix__.Import.Deferred.t
collect_output_and_wait t
closesstdin t
and then begins collecting the output produced ont
'sstdout
andstderr
, continuing to collect output untilt
terminates and the pipes forstdout
andstderr
are closed. Usually whent
terminates, the pipes are closed; however,t
could fork other processes which survive aftert
terminates and in turn keep the pipes open --collect_output_and_wait
will not become determined until both pipes are closed in all descendant processes.
type 'a run
= ?accept_nonzero_exit:int list -> ?argv0:string -> ?env:env -> ?prog_search_path:string list -> ?stdin:string -> ?working_dir:string -> prog:string -> args:string list -> unit -> 'a Async_unix__.Import.Deferred.t
run
create
s a process, feeds itstdin
if provided, andwait
s for it to complete. If the process exits with an acceptable status, thenrun
returns its stdout. If the process exits unacceptably, thenrun
returns an error indicating what went wrong that includes stdout and stderr.Acceptable statuses are zero, and any nonzero values specified in
accept_nonzero_exit
.Some care is taken so that an error displays nicely as a sexp---in particular, if the child's output can already be parsed as a sexp, then it will display as a sexp (rather than a sexp embedded in a string). Also, if the output isn't a sexp, it will be split on newlines into a list of strings, so that it displays on multiple lines rather than a single giant line with embedded "\n"'s.
run_lines
is likerun
but returns the lines of stdout as a string list, usingString.split_lines
.run_expect_no_output
is likerun
but expects the command to produce no output, and returns an error if the command does produce output.
val run : string Core.Or_error.t run
val run_exn : string run
val run_lines : string list Core.Or_error.t run
val run_lines_exn : string list run
val run_expect_no_output : unit Core.Or_error.t run
val run_expect_no_output_exn : unit run
type 'a collect
= ?accept_nonzero_exit:int list -> t -> 'a Async_unix__.Import.Deferred.t
collect_stdout_and_wait
andcollect_stdout_lines_and_wait
are likerun
andrun_lines
but work from an existing process instead of creating a new one.
val collect_stdout_and_wait : string Core.Or_error.t collect
val collect_stdout_and_wait_exn : string collect
val collect_stdout_lines_and_wait : string list Core.Or_error.t collect
val collect_stdout_lines_and_wait_exn : string list collect
val send_signal : t -> Core.Signal.t -> unit
Sends a signal to this process. This is safe to call concurrently with
wait t
, even if the Pid is reused after the process died.If the process was already terminated, the call succeeds and silently does nothing, regardless of whether or not the process was waited for.
module Lines_or_sexp : sig ... end
Lines_or_sexp
is useful for rendering a string nicely in a sexp, avoiding quoting if the string is multi-line or was produced by converting a sexp to a string.Output.sexp_of_t
usesLines_or_sexp
to nicely render stdout and stderr of a child process.