std.process
Functions for starting and interacting with other processes, and for working with the current process' execution environment.
Process_handling:
- spawnProcess spawns a new process, optionally assigning it an
arbitrary set of standard input, output, and error streams. The function returns immediately, leaving the child process to execute in parallel with its parent. All other functions in this module that spawn processes are built around
spawnProcess. - wait makes the parent process wait for a child process to
terminate. In general one should always do this, to avoid child processes becoming "zombies" when the parent process exits. Scope guards are perfect for this – see the spawnProcess documentation for examples. tryWait is similar to
wait, but does not block if the process has not yet terminated. - pipeProcess also spawns a child process which runs
in parallel with its parent. However, instead of taking arbitrary streams, it automatically creates a set of pipes that allow the parent to communicate with the child through the child's standard input, output, and/or error streams. This function corresponds roughly to C's
popenfunction. - execute starts a new process and waits for it
to complete before returning. Additionally, it captures the process' standard output and error streams and returns the output of these as a string.
- spawnShell, pipeShell and executeShell work like
spawnProcess,pipeProcessandexecute, respectively, except that they take a single command string and run it through the current user's default command interpreter.executeShellcorresponds roughly to C'ssystemfunction. - kill attempts to terminate a running process.
The following table compactly summarises the different process creation functions and how they relate to each other:
Other_functionality:
- pipe is used to create unidirectional pipes.
- environment is an interface through which the current process'
environment variables can be read and manipulated.
- escapeShellCommand and escapeShellFileName are useful
for constructing shell command lines in a portable way.
Copyright
License
Types 1
Manipulates _environment variables using an associative-array-like interface.
This class contains only static methods, and cannot be instantiated. See below for examples of use.
string opIndex(scope const(char)[] name) @safeRetrieves the value of the environment variable with the given `name`. --- auto path = environment["PATH"]; ---string get(scope const(char)[] name, string defaultValue = null) @safeRetrieves the value of the environment variable with the given `name`, or a default value if the variable doesn't exist.inout(char)[] opIndexAssign(return scope inout char[] value, scope const(char)[] name) @trustedAssigns the given `value` to the environment variable with the given `name`. If `value` is null the variable is removed from environment.void remove(scope const(char)[] name) @trusted nothrow @nogcRemoves the environment variable with the given `name`.bool opBinaryRight(string op : "in")(scope const(char)[] name) @trustedIdentify whether a variable is defined in the environment.void getImpl(scope const(char)[] name, scope void delegate(const(OSChar)[]) @safe sink) @trustedstring cachedToString(C)(scope const(C)[] v) @safeFunctions 3
int thisProcessID() @property @trusted nothrow @nogcReturns the process ID of the current process, which is guaranteed to be unique on the system.ThreadID thisThreadID() @property @trusted nothrow @nogcReturns the process ID of the current thread, which is guaranteed to be unique within the current process.