Constructor (variadic version). Note that by default, the environment will not be copied.
Constructor (variadic version, with environment copy).
Constructor.
Constructor.
Return an array with the process' arguments. This does not include the actual program name.
Set the process' arguments from the arguments received by the method.
Close and delete any pipe that may have been left open in a previous execution of a child process.
Explicitly close any resources held by this process object. It is recommended to always call this when you are done with the process.
Execute a process using the arguments as parameters to this method.
Execute a process using the command line arguments as parameters to this method.
Execute a process using the command line arguments as parameters to this method.
Execute a process using the arguments that were supplied to the constructor or to the args property.
Indicate whether the process is running or not.
Kill a running process. This method will not return until the process has been killed.
Set the process' arguments from the arguments received by the method.
Set the copyEnv flag. If set to true, then the environment will be copied from the current process. If set to false, then the environment is set from the env field.
Set the process' environment variables from the associative array received by the method. Returns a 'this' reference for chaining.
Set the GUI flag. Returns a reference to this process for chaining.
Set the process' executable filename, return 'this' for chaining
Set the redirect flags for the process. Return a reference to this process for chaining.
Set the working directory for the process. Returns a 'this' reference for chaining
Return an UTF-8 string with the process' command line.
Unconditionally wait for a process to end and return the reason and status code why the process ended.
If true, the environment from the current process will be copied to the child process.
Set the copyEnv flag. If set to true, then the environment will be copied from the current process. If set to false, then the environment is set from the env field.
Return an associative array with the process' environment variables.
Set the process' environment variables from the associative array received by the method.
Get the GUI flag.
Set the GUI flag.
Return the running process' ID.
Return the process' executable filename.
Set the process' executable filename.
Get the redirect flags for the process.
Set the redirect flags for the process.
Return the running process' standard error pipe.
Return the running process' standard input pipe.
Return the running process' standard output pipe.
Return the working directory for the process.
Set the working directory for the process.
Execute a process by looking up a file in the system path, passing the array of arguments and the the environment variables. This method is a combination of the execve() and execvp() POSIX system calls.
Split a string containing the command line used to invoke a program and return and array with the parsed arguments. The double-quotes (") character can be used to specify arguments with embedded spaces. e.g. first "second param" third
Convert an array of strings to an array of pointers to char with a terminating null character (C strings). The resulting array has a null pointer at the end. This is the format expected by the execv*() family of POSIX functions.
Convert an associative array of strings to an array of pointers to char with a terminating null character (C strings). The resulting array has a null pointer at the end. This is the format expected by the execv*() family of POSIX functions for environment variables.
Convert an associative array of strings to a buffer containing a concatenation of "<name>=<value>" strings separated by a null character and with an additional null character at the end of it. This is the format expected by the CreateProcess() Windows API for the environment variables.
Result returned by wait().
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);
The Process class is used to start external programs and communicate with them via their standard input, output and error streams.
You can pass either the command line or an array of arguments to execute, either in the constructor or to the args property. The environment variables can be set in a similar way using the env property and you can set the program's working directory via the workDir property.
To actually start a process you need to use the execute() method. Once the program is running you will be able to write to its standard input via the stdin OutputStream and you will be able to read from its standard output and error through the stdout and stderr InputStream respectively.
You can check whether the process is running or not with the isRunning() method and you can get its process ID via the pid property.
After you are done with the process, or if you just want to wait for it to end, you need to call the wait() method which will return once the process is no longer running.
To stop a running process you must use kill() method. If you do this you cannot call the wait() method. Once the kill() method returns the process will be already dead.
After calling either wait() or kill(), and no more data is expected on the pipes, you should call close() as this will clean the pipes. Not doing this may lead to a depletion of the available file descriptors for the main process if many processes are created.