spawnProcessDetached

Spawns a new process, optionally assigning it an arbitrary set of standard input, output, and error streams.

The function returns immediately, leaving the spawned process to execute in parallel with its parent.

The spawned process is detached from its parent, so you should not wait on the returned pid.

Parameters

args
Type: char[][]

An array which contains the program name as the zeroth element and any command-line arguments in the following elements.

env
Type: string[string]

Additional environment variables for the child process.

config
Type: Config

Flags that control process creation. Same as for spawnProcess.

workingDirectory
Type: char[]

The working directory for the new process.

pid
Type: ulong*

Pointer to variable that will get pid value in case spawnProcessDetached succeed. Not used if null.

Examples

1 import std.exception : assertThrown;
2 version(Posix) {
3     try {
4         auto devNull = File("/dev/null", "rwb");
5         ulong pid;
6         spawnProcessDetached(["whoami"], devNull, devNull, devNull, null, Config.none, "./test", &pid);
7         assert(pid != 0);
8 
9         assertThrown(spawnProcessDetached(["./test/nonexistent"]));
10         assertThrown(spawnProcessDetached(["./test/executable.sh"], devNull, devNull, devNull, null, Config.none, "./test/nonexistent"));
11         assertThrown(spawnProcessDetached(["./dub.json"]));
12         assertThrown(spawnProcessDetached(["./test/notreallyexecutable"]));
13     } catch(Exception e) {
14 
15     }
16 }
17 version(Windows) {
18     try {
19         ulong pid;
20         spawnProcessDetached(["whoami"], std.stdio.stdin, std.stdio.stdout, std.stdio.stderr, null, Config.none, "./test", &pid);
21 
22         assertThrown(spawnProcessDetached(["dub.json"]));
23     } catch(Exception e) {
24 
25     }
26 }

See Also

Meta