Starts a new process, creating pipes to redirect its standard input, output and/or error streams.
ProcessPipes pipeShell (
scope const(char) command,
Redirect redirect = Redirect
const(string[string]) env = cast(const(string[string]))null,
Config config = Config(Flags
scope const(char) workDir = null,
string shellPath = nativeShell()
pipeShell are convenient wrappers around
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
as detailed in the documentation for
parameters are forwarded straight to the underlying spawn functions,
and we refer to their documentation for details.
|args|| An array which contains the program name as the zeroth element
and any command-line arguments in the following elements.
|program|| The program name, without command-line arguments.
|command|| A shell command which is passed verbatim to the command
interpreter. (See |
|redirect|| Flags that determine which streams are redirected, and
how. See |
|env|| Additional environment variables for the child process.
|config|| Flags that control process creation. See |
|workDir||The working directory for the new process. By default the child process inherits the parent's working directory.|
|shellPath|| The path to the shell to use to run the specified program.
By default this is |
ProcessPipes object which contains
handles that communicate with the redirected streams of the child
process, along with a
Pid object that corresponds to the
ProcessException on failure to start the process.
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);
Lars Tandle Kyllingstad, Steven Schveighoffer, Vladimir Panteleev