A shell command which is passed verbatim to the command interpreter. (See spawnShell for details.)
Flags that determine which streams are redirected, and how. See Redirect for an overview of available flags.
Additional environment variables for the child process. (See spawnProcess for details.)
Flags that control process creation. See Config for an overview of available flags, and note that the retainStd... flags have no effect in this function.
The working directory for the new process. By default the child process inherits the parent's working directory.
The path to the shell to use to run the specified program. By default this is nativeShell.
A ProcessPipes object which contains std.stdio.File handles that communicate with the redirected streams of the child process, along with a Pid object that corresponds to the spawned process.
ProcessException on failure to start the process.
std.stdio.StdioException on failure to redirect any of the streams.
// my_application writes to stdout and might write to stderr auto pipes = pipeProcess("my_application", Redirect.stdout | Redirect.stderr); scope(exit) wait(pipes.pid); // Store lines of output. string[] output; foreach (line; pipes.stdout.byLine) output ~= line.idup; // Store lines of errors. string[] errors; foreach (line; pipes.stderr.byLine) errors ~= line.idup; // sendmail expects to read from stdin pipes = pipeProcess(["/usr/bin/sendmail", "-t"], Redirect.stdin); pipes.stdin.writeln("To: you"); pipes.stdin.writeln("From: me"); pipes.stdin.writeln("Subject: dlang"); pipes.stdin.writeln(""); pipes.stdin.writeln(message); // a single period tells sendmail we are finished pipes.stdin.writeln("."); // but at this point sendmail might not see it, we need to flush pipes.stdin.flush(); // sendmail happens to exit on ".", but some you have to close the file: pipes.stdin.close(); // otherwise this wait will wait forever wait(pipes.pid);
Starts a new process, creating pipes to redirect its standard input, output and/or error streams.
pipeProcess and pipeShell are convenient wrappers around spawnProcess and spawnShell, respectively, and automate the task of redirecting one or more of the child process' standard streams through pipes. Like the functions they wrap, these functions return immediately, leaving the child process to execute in parallel with the invoking process. It is recommended to always call wait on the returned ProcessPipes.pid, as detailed in the documentation for wait.
The args/program/command, env and config parameters are forwarded straight to the underlying spawn functions, and we refer to their documentation for details.