'a t value represent a process pipeline description, that can be evaluated using
eval into a value of type
'a. Note that creating an
'a t value has no effect. Effects are only performed when calling
module Context : sig ... end
Evaluate the given process in the given environment.
context is not specified, a temporary one is created. If you are calling
eval many times, then creating a context and reusing it is more efficient.
module Logged : sig ... end
module Traced : sig ... end
module Prim : sig ... end
module type Debugger = sig ... end
shexp_process allows one to plug a debugger in the evaluator.
Traced are essentially two non-interactive debuggers.
val return : 'a -> 'a t
Classic monad operations. Note that because shexp_process uses threads under the hood, you should be careful about using global mutable data structures. To communicate values between concurrent processes, use the
val fail : exn -> _ t
Create a process that fails with the given exception. Evaluation of this process will raise this exception.
fork a b represents two processes that are executed concurrently. The resulting process will block until both
b have finished and will return both of their results.
This is essentially the same as forking a system process: both process can independently change the current working directory, change their standard out, etc...
Regarding errors, if the evaluation of both processes fail, then only one the exceptions will be kept. It is not specified which one. You should use
Traced to get a full trace and see what exceptions are raised and where.
fork_all ps represents
List.length ps processes executed concurrently.
fork from pairs of elements to lists of elements.
A slightly more efficient version of
map (fork_all ps) ~f:(fun _ -> ())
protect ~finally t protects against execution errors.
finally is always executed, even if the evaluation of
Capture exceptions into the process monad. You can use this if the argument of
protect is the result of a function call.
For instance in the following code
finally wouldn't be executed:
let f () = raise Not_found protect ~finally (f ())
You can write instead:
protect ~finally (reify_exn f ())
val run : string -> string list -> unit t
Run an external program. This will fail if the external program does not exists, is signaled or exit with a non-zero exit code.
val run_exit_code : string -> string list -> int t
Run an external program and return its exit code. This will fail if the external program is signaled.
module Exit_status = Exit_status
Run an external program and return its exit status.
val run_bool : ?true_v:int list -> ?false_v:int list -> string -> string list -> bool t
Run an external program, returns
true if its exit code is part of
false if it is part of
val call : string list -> unit t
Same functions as the 'run' ones above, but take a string list instead. This way, the first element and the others are treated in a homogeneous way. It can ease prepending commands in specific circumstances, e.g.
if profile then call ("time" :: command) else call command
call ["grep"; "-i"; pattern; filename] is equivalent to
["-i"; pattern; filename]
val call_exit_code : string list -> int t
val call_bool : ?true_v:int list -> ?false_v:int list -> string list -> bool t
module Background_command : sig ... end
Start an external program but do not wait for its termination. If you never call
wait on the result, the process will become a zombie after it terminates.
Wait for a background command to terminate and return its exit status.
val find_executable : string -> string option t
Return the absolute path to the given command.
val find_executable_exn : string -> string t
val get_env : string -> string option t
Return the value associated to the given environment variable.
val get_env_exn : string -> string t
set_env var value k represents the process
k evaluated in a context where the envornment variable
var is set to
set_env var value k represents the process
k evaluated in a context where the environment variable
var is unset.
val cwd_logical : string t
Return the current working directory. Note that there is no guarantee that this directory exists. For instance if a component in this path has is renamed during the evaluation of the process, then this will be a dangling directory.
chdir dir k represents the process
k evaluated in a context where the current working directory is changed to
module Std_io = Std_io
Output a string on one of the standard io.
~n:() suppresses the newline output at the end.
val print : string -> unit t
val eprint : string -> unit t
val read_all : string t
Consume all standard input
Fold over lines in the input.
f is given the line with the end of line. Both
"\n" are treated as end of lines.
Fold over chunks separated by
sep in the input. This can be used in conjunction with commands that support ending entries in the output with a
'\000' such as
pipe ~connect:(aios, bio) a b is a process obtain by connecting the
a to the
b are evaluated in parallel (as with
(aio, bio) defaults to
pipe_pair a b is a the same as
pipe but returns the results of both
capture ios t = pipe_both ~connect:(ios, Stdin) read_all
capture_unit ios t = pipe ~connect:(ios, Stdin) read_all
redirect ios ?perm ~flags filename t redirects the following ios to a file in
flags are passed the same as for
Replace the given standard io by the given one. For instance to redirect stdout to stderr:
replace_io ~stdout:Stderr t
val temp_dir : string t
Return the current temporary directory
set_temp_dir dir k represents the process
k evaluated in a context where the current temporary directory is set to
with_temp_file ~prefix ~suffix f is a process that creates a temporary file and passes it to
f. The file is created inside the temporary directory.
When the process returned by
f finishes, the file is removed.
with_temp_file but creates a directory. The directory and its contents are deleted when the process finishes.
val chown : string -> uid:int -> gid:int -> unit t
val rm : string -> unit t
val rmdir : string -> unit t
val rename : string -> string -> unit t
val readdir : string -> string list t
val file_exists : string -> bool t
val rm_rf : string -> unit t
Recursively remove a tree
val sleep : float -> unit t
module Infix : sig ... end
module Let_syntax : sig ... end
Open this module when using
module List : sig ... end