License:
BSD style: see license.txtAuthor:
Juan Jose ComellasExamples:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | try { auto p = new Process ("ls -al", null); p.execute; Stdout.formatln ("Output from {}:", p.programName); Stdout.copy (p.stdout).flush; auto result = p.wait; Stdout.formatln ("Process '{}' ({}) exited with reason {}, status {}", p.programName, p.pid, cast(int) result.reason, result.status); } catch (ProcessException e) Stdout.formatln ("Process execution failed: {}", e); |
Params:
args | array of strings with the process' arguments. If there is exactly one argument, it is considered to contain the entire command line including parameters. If you pass only one argument, spaces that are not intended to separate parameters should be embedded in quotes. The arguments can also be empty. |
Examples:
1 2 | auto p = new Process("myprogram", "first argument", "second", "third"); auto p = new Process("myprogram \"first argument\" second third"); |
Params:
copyEnv | if true, the environment is copied from the current process. |
args | array of strings with the process' arguments. If there is exactly one argument, it is considered to contain the entire command line including parameters. If you pass only one argument, spaces that are not intended to separate parameters should be embedded in quotes. The arguments can also be empty. |
Examples:
1 2 | auto p = new Process(true, "myprogram", "first argument", "second", "third"); auto p = new Process(true, "myprogram \"first argument\" second third"); |
Params:
command | string with the process' command line; arguments that have embedded whitespace must be enclosed in inside double-quotes ("). |
env | associative array of strings with the process' environment variables; the variable name must be the key of each entry. |
Examples:
1 2 3 4 5 6 7 8 | char[] command = "myprogram \"first argument\" second third"; char[][char[]] env; // Environment variables env["MYVAR1"] = "first"; env["MYVAR2"] = "second"; auto p = new Process(command, env) |
Params:
args | array of strings with the process' arguments; the first argument must be the process' name; the arguments can be empty. |
env | associative array of strings with the process' environment variables; the variable name must be the key of each entry. |
Examples:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | char[][] args; char[][char[]] env; // Process name args ~= "myprogram"; // Process arguments args ~= "first argument"; args ~= "second"; args ~= "third"; // Environment variables env["MYVAR1"] = "first"; env["MYVAR2"] = "second"; auto p = new Process(args, env) |
Returns:
an int with the process ID if the process is running; -1 if not.Remarks:
The first element of the array must be the name of the process' executable.Returns:
the arugments that were set.Examples:
1 | p.args("myprogram", "first", "second argument", "third"); |
Remarks:
The first element of the array must be the name of the process' executable.Returns:
a reference to this for chainingExamples:
1 | p.setArgs("myprogram", "first", "second argument", "third").execute(); |
Returns:
A reference to this for chainingParams:
env | associative array of strings containing the environment variables for the process. The variable name should be the key used for each entry. |
Returns:
the env set.Examples:
1 2 3 4 5 6 | char[][char[]] env; env["MYVAR1"] = "first"; env["MYVAR2"] = "second"; p.env = env; |
Params:
env | associative array of strings containing the environment variables for the process. The variable name should be the key used for each entry. |
Returns:
A reference to this process objectExamples:
1 2 3 4 5 6 | char[][char[]] env; env["MYVAR1"] = "first"; env["MYVAR2"] = "second"; p.setEnv(env).execute(); |
Returns:
a string with the working directory; null if the working directory is the current directory.Params:
dir | a string with the working directory; null if the working directory is the current directory. |
Returns:
the directory set.Params:
dir | a string with the working directory; null if the working directory is the current directory. |
Returns:
a reference to this process.Returns:
a write-only PipeConduit connected to the child process' stdin.Remarks:
The stream will be null if no child process has been executed, or the standard input stream was not redirected.Returns:
a read-only PipeConduit connected to the child process' stdout.Remarks:
The stream will be null if no child process has been executed, or the standard output stream was not redirected.Returns:
a read-only PipeConduit connected to the child process' stderr.Remarks:
The stream will be null if no child process has been executed, or the standard error stream was not redirected.Throws:
ProcessCreateException if the process could not be created successfully; ProcessForkException if the call to the fork() system call failed (on POSIX-compatible platforms).Remarks:
The process must not be running and the provided list of arguments must not be empty. If there was any argument already present in the args member, they will be replaced by the arguments supplied to the method.Deprecated:
Use constructor or properties to set up process for execution.Params:
command | string with the process' command line; arguments that have embedded whitespace must be enclosed in inside double-quotes ("). |
env | associative array of strings with the process' environment variables; the variable name must be the key of each entry. |
Throws:
ProcessCreateException if the process could not be created successfully; ProcessForkException if the call to the fork() system call failed (on POSIX-compatible platforms).Remarks:
The process must not be running and the provided list of arguments must not be empty. If there was any argument already present in the args member, they will be replaced by the arguments supplied to the method.Deprecated:
use properties or the constructor to set these parameters instead.Params:
args | array of strings with the process' arguments; the first argument must be the process' name; the arguments can be empty. |
env | associative array of strings with the process' environment variables; the variable name must be the key of each entry. |
Throws:
ProcessCreateException if the process could not be created successfully; ProcessForkException if the call to the fork() system call failed (on POSIX-compatible platforms).Remarks:
The process must not be running and the provided list of arguments must not be empty. If there was any argument already present in the args member, they will be replaced by the arguments supplied to the method.Deprecated:
Use properties or the constructor to set these parameters instead.Examples:
1 2 3 4 5 6 7 | auto p = new Process(); char[][] args; args ~= "ls"; args ~= "-l"; p.execute(args, null); |
Returns:
A reference to this process object for chaining.Throws:
ProcessCreateException if the process could not be created successfully; ProcessForkException if the call to the fork() system call failed (on POSIX-compatible platforms).Remarks:
The process must not be running and the list of arguments must not be empty before calling this method.Returns:
The return value is a Result struct, which has two members: reason and status. The reason can take the following values: Process.Result.Exit: the child process exited normally; status has the process' return code. Process.Result.Signal: the child process was killed by a signal; status has the signal number that killed the process. Process.Result.Stop: the process was stopped; status has the signal number that was used to stop the process. Process.Result.Continue: the process had been previously stopped and has now been restarted; status has the signal number that was used to continue the process. Process.Result.Error: We could not properly wait on the child process; status has the errno value if the process was running and -1 if not.Remarks:
You can only call wait() on a running process once. The Signal, Stop and Continue reasons will only be returned on POSIX-compatible platforms. Calling wait() will not clean the pipes as the parent process may still want the remaining output. It is however recommended to call close() when no more content is expected, as this will close the pipes.Throws:
ProcessKillException if the process could not be killed; ProcessWaitException if we could not wait on the process after killing it.Remarks:
After calling this method you will not be able to call wait() on the process. Killing the process does not clean the attached pipes as the parent process may still want/need the remaining content. However, it is recommended to call close() on the process when it is no longer needed as this will clean the pipes.