Os.CmdExecuting commands.
val path_search :
?win_exe:bool ->
?path:Fpath.t list ->
unit ->
Cmd.tool_searchpath_search ~win_exe ~path () cmd searches the tool of cmd in the path directories. If the tool:
path. path defaults to the environment variable PATH parsed with Fpath.list_of_search_path.cmd is returned if that is the case (possibly by altered by the win_exe behaviour, see below). If the path is relative it is tested relative to the process' current working directory.If win_exe is true (defaults to Stdlib.Sys.win32) an .exe suffix is added to the command's tool if it doesn't already have one. .
val find : ?search:Cmd.tool_search -> Cmd.t -> Cmd.t optionfind ~search cmd is cmd with its B0_std.Cmd.tool resolved to the executable file for the tool specified by cmd using search (defaults to path_search ()) or Ok None if the tool cannot be found.
val find_first : ?search:Cmd.tool_search -> Cmd.t list -> Cmd.t optionfind_first ?search cmds is List.find_map (find ?search) cmds.
val get : ?search:Cmd.tool_search -> Cmd.t -> (Cmd.t, string) Stdlib.resultget is like find except but return an error message if Ok None is returned.
val get_first :
?search:Cmd.tool_search ->
Cmd.t list ->
(Cmd.t, string) Stdlib.resultget_first_tool cmds is the first command of cmds that can be found with find or an error if none is found.
pp_status is a formatter for process exit statuses of the form:
"exited %d" for `Exited _ values"signaled %s" for `Signaled _ valuepp_cmd_status is a formatter for command process exit statuses of the form: "cmd [%a]: %a".
val in_string : string -> stdiin_string s is a standard input that reads the string s.
val in_fd : close:bool -> Unix.file_descr -> stdiin_fd ~close fd is a standard input that reads from file descriptor fd. If close is true, fd is closed after the process is spawn.
val in_stdin : stdiin_stdin is in_fd ~close:false Unix.stdin, a standard input that reads from the current process standard input.
val in_null : stdiin_null is in_file File.null.
out_file ~force ~make_path file is a standard output that writes to file file.
make_path is true and the parent directory of file does not exist the whole path to the parent is created as needed with permission 0o755 (readable and traversable by everyone, writable by the user).force is true and file exists at call time as a regular file it tries to overwrite it, in all other cases the function errors if file exists.mode are the permissions of the written file; they default to 0o644, readable by everyone, writable by the user.val out_fd : close:bool -> Unix.file_descr -> stdoout_fd ~close fd is a standard output that writes to file descriptor fd. If close is true, fd is closed after the process spawn.
val out_stdout : stdoout_stdout is out_fd ~close:false Unix.stdout
val out_stderr : stdoout_stderr is out_fd ~close:false Unix.stderr
val out_null : stdoout_null is out_file File.null
These functions wait for the command to complete before proceeding.
val run_status :
?env:Env.assignments ->
?cwd:Fpath.t ->
?stdin:stdi ->
?stdout:stdo ->
?stderr:stdo ->
Cmd.t ->
(status, string) Stdlib.resultrun_status ~env ~cwd ~stdin ~stdout ~stderr cmd runs and waits for the completion of cmd in environment env with current directory cwd and standard IO connections stdin, stdout and stderr.
env defaults to Env.current_assignments ()cwd defaults to Dir.cwd ()stdin defaults to in_stdinstdout defaults to out_stdoutstderr defaults to out_stderrval run_status_out :
?env:Env.assignments ->
?cwd:Fpath.t ->
?stdin:stdi ->
?stderr:[ `Stdo of stdo | `Out ] ->
trim:bool ->
Cmd.t ->
(status * string, string) Stdlib.resultrun_status_out is like run_status except stdout is read from the process to a string. The string is String.trimed if trim is true (default). If stderr is `Out the process' stderr is redirected to stdout and thus read back in the string aswell.
val run :
?env:Env.assignments ->
?cwd:Fpath.t ->
?stdin:stdi ->
?stdout:stdo ->
?stderr:stdo ->
Cmd.t ->
(unit, string) Stdlib.resultrun is run_status with non-`Exited 0 statuses turned into errors via pp_cmd_status.
val run_out :
?env:Env.assignments ->
?cwd:Fpath.t ->
?stdin:stdi ->
?stderr:[ `Stdo of stdo | `Out ] ->
trim:bool ->
Cmd.t ->
(string, string) Stdlib.resultrun_out is run_status_out with non-`Exited 0 statuses reporting the captured output (if any) prefixed by pp_cmd_status.
Note. In contrast to waitpid(2) the following API does not allow to collect any child process completion. There are two reasons: first this is not supported on Windows, second this is anti-modular.
val pid_to_int : pid -> intpid_to_int pid is the system identifier for process identifier pid.
val spawn :
?env:Env.assignments ->
?cwd:Fpath.t ->
?stdin:stdi ->
?stdout:stdo ->
?stderr:stdo ->
Cmd.t ->
(pid, string) Stdlib.resultspawn ~env ~cwd ~stdin ~stdout ~stderr cmd spawns command cmd in environment env with current directory cwd and standard IO connections stdin, stdout and stderr. env defaults to Env.current_assignments (), cwd to Dir.cwd (), stdin to in_stdin, stdout to out_stdout and stderr to out_stderr.
spawn_poll_status pid tries to collect the exit status of command spawn pid. If block is false, Ok None is immediately returned if pid has not terinated yet.
spawn_wait_status blocks and waits for pid's termination status to become available.
val spawn_wait : pid -> (unit, string) Stdlib.resultspawn_wait is like spawn_wait_status but with non-`Exited 0 statuses turned into errors with pp_cmd_status
val kill : pid -> int -> (unit, string) Stdlib.resultkill pid signal sends signal signal to the process pid.
Windows. Only the Sys.sigkill signal is emulated.
type spawn_tracer =
pid option ->
Env.assignments option ->
cwd:Fpath.t option ->
Cmd.t ->
unitThe type for spawn tracers. Called with each blocking and non-blocking spawned command aswell as execv. The function is given the process identifier of the spawn (or None in case of execv), the environment if different from the program's one, the current working directory if different from the program's one and the actual command.
val spawn_tracer_nop : spawn_tracerspawn_tracer_nop is a spawn tracer that does nothing.
val spawn_tracer_log : Log.level -> spawn_tracerspawn_tracer_log level is a spawn tracer that logs with level level. If level is Log.level.Quiet this is spawn_tracer_nop.
val spawn_tracer : unit -> spawn_tracertracer () is the current spawn tracer. Initially this is spawn_tracer_log Log.Debug.
val set_spawn_tracer : spawn_tracer -> unitset_tracer t sets the current spawn tracer to t.
Windows. On Windows a program executing an execv* function yields back control to the terminal as soon as the child starts (vs. ends on POSIX). This entails all sorts of unwanted behaviours. To workaround this, the following function executes, on Windows, the file as a spawned child process which is waited on for completion via waitpid(2). Once the child process has terminated the calling process is immediately exited with the status of the child.
val execv :
?env:Env.assignments ->
?cwd:Fpath.t ->
?argv0:string ->
Cmd.t ->
('a, string) Stdlib.resultexecv ~env ~cwd cmd executes the realpath pointed by B0_std.Cmd.tool cmd as a new process in environment with cmd as the Sys.argv of this process. The function only returns in case of error. env defaults to B0_std.Os.Env.current_assignments (), cwd to B0_std.Os.Dir.cwd (). If argv0 is specified it is used instead of cmd's tool for Sys.argv.(0).
type t = Cmd.tExit needs that alias to refer to B0_std.Cmd.t.