Module OS.Cmd
Running commands.
Command existence
Running commands
val run : ?err:fpath -> Cmd.t -> unit result
run cmd
runs the commandcmd
.std{i,o,err}
are connected to the invoking process' standard channels. Iferr
is specifiedstderr
is redirected to the given file (e.g.File.null
).
val run_status : ?err:fpath -> Cmd.t -> [ `Exited of int ] result
run_status cmd
is like Running commands, but doesn't error on non-zero exit status.
Capturing standard output
type run_status
= Cmd.t * [ `Exited of int ]
The type for run statuses, the command that was run and the run status.
val success : ('a * run_status) result -> 'a result
success r
is:Ok v
ifr = Ok (v, (_, `Exited 0))
Error _
otherwise. Non`Exited 0
statuses are turned into an error message.
val out_string : ?trim:bool -> run_out -> (string * run_status) result
out_string ~trim o
captures the standard outputo
as astring
. Iftrim
istrue
(default) the result is passed throughString.trim
.
val out_lines : ?trim:bool -> run_out -> (string list * run_status) result
out_lines ~trim
is likeout_string
but the result is cut on newlines ('\n'
).
val out_file : fpath -> run_out -> (unit * run_status) result
out_file f o
writes the standard outputo
to filef
.
val out_stdout : run_out -> (unit * run_status) result
out_stdout o
redirects the standard outputo
to the current process standard output.
val to_string : ?trim:bool -> run_out -> string result
to_string
is(out_string ?trim o |> success)
.
val to_lines : ?trim:bool -> run_out -> string list result
to_lines ?trim o
is(out_string ?trim o |> success)
.
val run_out : ?err:fpath -> Cmd.t -> run_out
run_out cmd
represents the standard output of the command runcmd
.std{i,err}
are connected to the invoking prcoess stream and standard output can be consumed withto_string
,to_lines
orto_file
. Iferr
is specifiedstderr
is redirected to the given file.