Config

Flags that control the behaviour of process creation functions in this module. Most flags only apply to spawnProcess and spawnShell.

Use bitwise OR to combine flags.

Values

ValueMeaning
none0
newEnv1

By default, the child process inherits the parent's environment, and any environment variables passed to spawnProcess will be added to it. If this flag is set, the only variables in the child process' environment will be those given to spawnProcess.

retainStdin2

Unless the child process inherits the standard input/output/error streams of its parent, one almost always wants the streams closed in the parent when spawnProcess returns. Therefore, by default, this is done. If this is not desirable, pass any of these options to spawnProcess.

retainStdout4

ditto

retainStderr8

ditto

suppressConsole16

On Windows, if the child process is a console application, this flag will prevent the creation of a console window. Otherwise, it will be ignored. On POSIX, suppressConsole has no effect.

inheritFDs32

On POSIX, open file descriptors are by default inherited by the child process. As this may lead to subtle bugs when pipes or multiple threads are involved, spawnProcess ensures that all file descriptors except the ones that correspond to standard input/output/error are closed in the child process when it starts. Use inheritFDs to prevent this.

On Windows, this option has no effect, and any handles which have been explicitly marked as inheritable will always be inherited by the child process.

detached64

Spawn process in detached state. This removes the need in calling wait to clean up the process resources.

Note: Calling wait or kill with the resulting Pid is invalid.

stderrPassThrough128

By default, the execute and executeShell functions will capture child processes' both stdout and stderr. This can be undesirable if the standard output is to be processed or otherwise used by the invoking program, as execute's result would then contain a mix of output and warning/error messages.

Specify this flag when calling execute or executeShell to cause invoked processes' stderr stream to be sent to std.stdio.stderr, and only capture and return standard output.

This flag has no effect on spawnProcess or spawnShell.

Examples

auto logFile = File("myapp_error.log", "w");

// Start program, suppressing the console window (Windows only),
// redirect its error stream to logFile, and leave logFile open
// in the parent process as well.
auto pid = spawnProcess("myapp", stdin, stdout, logFile,
                        Config.retainStderr | Config.suppressConsole);
scope(exit)
{
    auto exitCode = wait(pid);
    logFile.writeln("myapp exited with code ", exitCode);
    logFile.close();
}

Meta

Suggestion Box / Bug Report