Tool existence and search
find_tool ~search cmd
is the path to the tool of cmd
as found by the tool search procedure in search
.
get_tool cmd
is like find_tool
except it errors if the tool path cannot be found.
exists ~search cmd
is Ok true
if find_tool
finds a path and Ok false
if it does not.
must_exist ~search cmd
is Ok cmd
if get_tool
succeeds.
resolve ~search cmd
is like must_exist
except the tool of the resulting command value has the path to the tool of cmd
as determined by get_tool
.
search_path_dirs ~sep s
parses sep
seperated file paths from s
. sep
is not allowed to appear in the file paths, it defaults to ";"
if Sys
.win32 is true
and ":"
otherwise.
Command runs
Run statuses & information
The type for run statuses the run information and the process exit status.
val success : ('a * run_status, 'e) result -> ('a, 'e) result
success r
is:
Ok v
ifr = Ok (v, (_, `Exited 0))
Error _
otherwise. Non`Exited 0
statuses are turned into an error message.
Run standard errors
err_file f
is a standard error that writes to file f
. If append
is true
(defaults to false
) the data is appended to f
.
val err_null : run_err
err_null
is err_file File.null
.
val err_run_out : run_err
err_run_out
is a standard error that is redirected to the run's standard output.
val err_stderr : run_err
err_stderr
is a standard error that is redirected to the current process standard error.
Run standard inputs
val in_string : string -> run_in
in_string s
is a standard input that reads s
.
val in_null : run_in
in_null
is in_file File.null
.
val in_stdin : run_in
in_stdin
is a standard input that reads from the current process standard input.
Run standard outputs
val out_string : ?trim:bool -> run_out -> (string * run_status, 'e) result
out_string ~trim o
captures the standard output o
as a string. If trim
is true
(default) the result is passed through String
.trim.
val out_lines : ?trim:bool -> run_out -> (string list * run_status, 'e) result
out_lines
is like out_string
but the result is splitted on newlines ('\n'
). If the standard output is empty then the empty list is returned.
val out_file : ?append:bool -> Fpath.t -> run_out -> (unit * run_status, 'e) result
out_file f o
writes the standard output o
to file f
. If append
is true
(defaults to false
) the data is appended to f
.
out_run_in o
is a run input that can be used to feed the standard output of o
to the standard input of another, single, command run. Note that when the function returns the command run of o
may not be terminated yet. The run using the resulting input will report an unsucessful status or error of o
rather than its own error.
val out_null : run_out -> (unit * run_status, 'e) result
out_null o
is out_file File.null o
.
val out_stdout : run_out -> (unit * run_status, 'e) result
to_stdout o
redirects the standard output o
to the current process standard output.
Extracting success
to_string ~trim o
is (out_string ~trim o |> success)
.
to_lines ~trim o
is (out_lines ~trim o |> success)
.
to_file ?append f o
is (out_file ?append f o |> success)
.
Run specifications
run_io ~env ~err cmd i
represents the standard output of the command run cmd
performed in process environment env
with its standard error output handled according to err
(defaults to err_stderr
) and standard input connected to i
. Note that the command run is not started before the output is consumed, see run standard outputs.
run_out ?env ?err cmd
is (in_stdin |> run_io ?env ?err cmd)
.
run_in ?env ?err cmd i
is (run_io ?env ?err cmd |> to_stdout)
.
run ?env ?err cmd
is (in_stdin |> run_io ?env ?err cmd |> to_stdout)
.
run_status ?env ?err ?quiet cmd
is (in_stdin |> run_io ?env ?err ?cmd |> out_stdout)
and extracts the run status.
If quiet
is true
(defaults to false
), in_stdin
and out_stdout
are respectively replaced by in_null
and out_null
and err
defaults to err_null
rather than err_stderr
.