ProcessMonitor

Spawns and monitors sub-processes.

Monitoring processes in a safe way is expensive. This implementation requires spawning 3 threads per process. Use this sparingly.

This class is entirely thread and fibre safe. Methods that block only block on the fibre (not the thread), and locks are used to prevent data-races.

Constructors

this
this()
this(string[] args, Tuple!(string, string)[] env, string workingDir)

Creates a new ProcessMonitor.

Members

Aliases

EventCallback
alias EventCallback = void delegate()

Callack for termination

FileCallback
alias FileCallback = void delegate(string)

Callback for stdout and stderr events

Functions

closeStdin
void closeStdin()

Closes the monitor's end of stdin for the process.

kill
void kill(int signal)

Sends a signal to the process.

send
void send(string message)

Sends a line of input to the monitored process's stdin.

start
void start(string[] args, Tuple!(string, string)[] env, string workingDir)

Start a monitored process given the arguments (args), environment (env) and working directory (workingDir).

wait
int wait()

Block on the current fibre until the process has exited.

Properties

killTimeout
Duration killTimeout [@property getter]
Duration killTimeout [@property setter]

The time to wait before the process is force-killed by the monitor after being asked to stop. Defaults to 20 seconds.

pid
Pid pid [@property getter]

Returns the pid of the running process, or the last process run. Otherwise returns Pid.init.

running
bool running [@property getter]

Returns whether or not the monitored process is currently running.

stderrCallback
FileCallback stderrCallback [@property setter]

Sets the callback for when a line from the monitored process's stderr is read.

stdoutCallback
FileCallback stdoutCallback [@property setter]

Sets the callback for when a line from the monitored process's stdout is read.

terminateCallback
EventCallback terminateCallback [@property setter]

Sets the callback for when the monitored process exits.

Meta