Up

Module Process = Async_unix.Process

Signature

type t
val sexp_of_t : t -> Sexplib.Sexp.t
val pid : t -> Core.Std.Pid.t

accessors

val stdin : t -> Async_unix.Writer.t
val stdout : t -> Async_unix.Reader.t
val stderr : t -> Async_unix.Reader.t
type env = Core.Std.Unix.env
val env_of_sexp : Sexplib.Sexp.t -> env
val sexp_of_env : env -> Sexplib.Sexp.t
type 'a with_create_args = ?working_dir:string -> ?env:env -> prog:string -> args:string list -> unit -> 'a

with_create_args specifies the arguments used to create a child process.

create ~prog ~args ?working_dir ?env () uses fork and exec to create a child process that runs the executable prog with args as arguments. It creates pipes to communicate with the child process's stdin, stdout, and stderr.

Unlike exec, args should not include prog as the first argument.

If working_dir is supplied, then the child process will chdir() there before calling exec().

env specifies the environment of the child process.

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.).

wait t = Unix.waitpid (pid t)

module Output : sig .. end
collect_output_and_wait t closes stdin t and then begins collecting the output produced on t's stdout and stderr, continuing to collect output until t terminates and the pipes for stdout and stderr are closed.
val collect_output_and_wait : t -> Output.t Async_unix.Import.Deferred.t
val run : ?accept_nonzero_exit:int list -> string Core.Std.Or_error.t Async_unix.Import.Deferred.t with_create_args

run creates a process and waits for it to complete. If the process exits with an acceptable status, then run returns its stdout. Acceptable statuses are zero, and any nonzero values specified in accept_nonzero_exit. If the process exits unacceptably, then run returns an error indicating what went wrong that includes stdout and stderr.

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 " "'s.

val run_lines : ?accept_nonzero_exit:int list -> string list Core.Std.Or_error.t Async_unix.Import.Deferred.t with_create_args

run_lines is like run but returns the lines of stdout as a string list, using String.split_lines.

val run_expect_no_output : ?accept_nonzero_exit:int list -> unit Core.Std.Or_error.t Async_unix.Import.Deferred.t with_create_args

run_expect_no_output is like run but expects the command to produce no output, and returns an error if the command does produce output.

collect_stdout_and_wait and collect_stdout_lines_and_wait are like run and run_lines but work from an existing process instead of creating a new one.

val collect_stdout_and_wait : ?accept_nonzero_exit:int list -> t -> string Core.Std.Or_error.t Async_unix.Import.Deferred.t
val collect_stdout_lines_and_wait : ?accept_nonzero_exit:int list -> t -> string list Core.Std.Or_error.t Async_unix.Import.Deferred.t