Module Async_unix.Process
Async.Process is for creating child processes of the current process, and communicating with children via their stdin, stdout, and stderr. Async.Process is the Async analog of Core.Unix.create_process and related functions.
val sexp_of_t : t -> Ppx_sexp_conv_lib.Sexp.t
val pid : t -> Core.Pid.taccessors
type env= Core.Unix.env
val sexp_of_env : env -> Ppx_sexp_conv_lib.Sexp.tval 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.tcreate ~prog ~args ()usesCore.Unix.create_process_envto create a child process that runs the executableprogwithargsas arguments. It creates pipes to communicate with the child process'sstdin,stdout, andstderr.Unlike
exec,argsshould not includeprogas the first argument.If
buf_lenis supplied, it determines the size of the reader and writer buffers used to communicate with the child process'sstdin,stdout, andstderr.If
stdinis supplied, then the writer to the child's stdin will have~raise_when_consumer_leaves:falseand~buffer_age_limit:`Unlimited, which makes it more robust.envspecifies the environment of the child process.If
working_diris supplied, then the child process willchdir()there before callingexec().If
argv0is given, it is used (instead ofprog) as the first element of theargvarray passed toexec.createreturnsErrorif 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 toexecetc.).createdoes not returnErrorif the binary exits with non-zero exit code; instead, it returnsOK t, wherewait treturns anError.See
Core.Unix.create_process_envfor more details.
val create : t Core.Or_error.t createval create_exn : t createval wait : t -> Core.Unix.Exit_or_signal.t Async_unix__.Import.Deferred.twait t = Unix.waitpid (pid t)
module Output : sig ... endval collect_output_and_wait : t -> Output.t Async_unix__.Import.Deferred.tcollect_output_and_wait tclosesstdin tand then begins collecting the output produced ont'sstdoutandstderr, continuing to collect output untiltterminates and the pipes forstdoutandstderrare closed. Usually whentterminates, the pipes are closed; however,tcould fork other processes which survive aftertterminates and in turn keep the pipes open --waitwill not become determined until both pipes are closed in all descendant processes.
type 'a run= ?accept_nonzero_exit:int list -> ?env:env -> ?stdin:string -> ?working_dir:string -> prog:string -> args:string list -> unit -> 'a Async_unix__.Import.Deferred.truncreates a process, feeds itstdinif provided, andwaits for it to complete. If the process exits with an acceptable status, thenrunreturns its stdout. If the process exits unacceptably, thenrunreturns 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_linesis likerunbut returns the lines of stdout as a string list, usingString.split_lines.run_expect_no_outputis likerunbut expects the command to produce no output, and returns an error if the command does produce output.
val run : string Core.Or_error.t runval run_exn : string runval run_lines : string list Core.Or_error.t runval run_lines_exn : string list runval run_expect_no_output : unit Core.Or_error.t runval run_expect_no_output_exn : unit run
type 'a collect= ?accept_nonzero_exit:int list -> t -> 'a Async_unix__.Import.Deferred.tcollect_stdout_and_waitandcollect_stdout_lines_and_waitare likerunandrun_linesbut work from an existing process instead of creating a new one.
val collect_stdout_and_wait : string Core.Or_error.t collectval collect_stdout_and_wait_exn : string collectval collect_stdout_lines_and_wait : string list Core.Or_error.t collectval collect_stdout_lines_and_wait_exn : string list collect
module Lines_or_sexp : sig ... endLines_or_sexpis 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_tusesLines_or_sexpto nicely render stdout and stderr of a child process.