Subprocess.CoreSourceHere follows the interface defined in the Core module. This module is included in most of the user-facing modules for convenience, so you may stumble across its documentation in several places.
The interface defined here is needed to do almost anything with the library.
We begin with a set of placeholder types which are used to represent handles to the i/o streams of running processes (namely, stdin, stdout and stderr). Since only streams that have pipes in the parent process are really interactive in any way, these non-interactive place holders are used in other cases. Their main function is to provide type-level information about the streams.
When the library raises, it always raises a Subprocess_error of string.
In and Out are I/O wrappers for process streams. It's thanks to these bad boys we can have such verbose types.
type ('stdin, 'stdout, 'stderr) t = {pid : int;cmd : ('stdin, 'stdout, 'stderr) Cmd.t;stdin : 'stdin In.t;stdout : 'stdout Out.t;stderr : 'stderr Out.t;close : ?mode:Unix.wait_flag list -> unit -> Exit.t;}The type t represents a process which may still be running. Some of the higher-level functions don't expose it directly, but almost everything else is implemented in terms of this type.
Apply () to the close property to close any managed file descriptors and wait for the process to exit.
Obligatory pretty printer, for your debugging pleasure.
What follows are some helper functions which fetch pipes to a running process for interactive reading and writting. They shadow channels with the same names in the standard library. Probably a good reason to only open Subprocess within a limited scope.
If you try to use one of these functions to access a stream which isn't a pipe, it's a type error.
Teeny, tiny, leaky wrapper for Unix.waitpid refer to its documentation
Find out if your process has finished executing.
val cmd :
?prog:string ->
?env:string list ->
?block:bool ->
string list ->
(stdin, stdout, stderr) Cmd.tHelper funtions for constructing Cmd.t. The optional prog argument is mainly for if you don't want your path to be searched for the executable.
env is a list of strings with the format "NAME=value". block may be set to false for non-blocking I/O on pipes. This one setting is used with any pipes which are used for I/O. Remember to catch Sys_blocked_io when doing I/O with any non-blocking pipes.
Both env and block can also be set with combinators.
redirect stdin to a pipe for writing.
redirect stdout to a pipe for reading.
redirect stdout to a pipe for writing.
val channel_in :
in_channel ->
(stdin, 'stdout, 'stderr) Cmd.t ->
(channel, 'stdout, 'stderr) Cmd.tredirect stdin to an in_channel.
val channel_out :
out_channel ->
('stdin, stdout, 'stderr) Cmd.t ->
('stdin, channel, 'stderr) Cmd.tredirect stdout to an out_channel.
val channel_err :
out_channel ->
('stdin, 'stdout, stderr) Cmd.t ->
('stdin, 'stdout, channel) Cmd.tredirect stderr to an out_channel.
redirect stdin to an named file. Similar to < in the shell.
redirect stdout to an named file. Similar to > in the shell.
redirect stderr to an named file. Similar to 2> in the shell.
redirect stdout to an named file for appending. Similar to >> in the shell.
redirect stderr to an named file for appending. Similar to 2>> in the shell.
redirect stdout to /dev/null. similar to > /dev/null in the shell
redirect stderr to /dev/null. similar to 2> /dev/null in the shell
Set additional environment variables. Variables are passed in as a list of strings with the format "NAME=value".