Spawn

class Spawn {
string workingDirectory;
string[] argv;
string[] envp;
GSpawnFlags flags;
GSpawnChildSetupFunc childSetup;
void* userData;
GPid childPid;
FILE* standardInput;
FILE* standardOutput;
FILE* standardError;
GError* error;
int stdIn;
int stdOut;
int stdErr;
int exitStatus;
char* strOutput;
char* strError;
ChildWatch externalWatch;
}

Constructors

this
this(string program, string[] envp)

Creates a Spawn for execution.

this
this(string[] program, string[] envp)

Creates a Spawn for execution.

Members

Functions

addChildWatch
void addChildWatch(ChildWatch dlg)

Adds a delegate to be notified on the end of the child process.

addParm
void addParm(string parm)

Adds a parameter to the execution program

close
void close()

Closes all open streams and child process.

commandLineSync
int commandLineSync(ChildWatch externalWatch, bool delegate(string) readOutput, bool delegate(string) readError)

Executes a command synchronasly and optionally calls delegates for sysout, syserr and end of job

execAsyncWithPipes
int execAsyncWithPipes(ChildWatch externalWatch, bool delegate(string) readOutput, bool delegate(string) readError)

Executes the prepared process

getLastError
string getLastError()

Gets the last error message

Static functions

async
bool async(string workingDirectory, string[] argv, string[] envp, GSpawnFlags flags, GSpawnChildSetupFunc childSetup, void* userData, GPid childPid)

See Spawn.asyncWithPipes for a full description; this function simply calls the Spawn.asyncWithPipes without any pipes.

asyncWithFds
bool asyncWithFds(string workingDirectory, string[] argv, string[] envp, GSpawnFlags flags, GSpawnChildSetupFunc childSetup, void* userData, GPid childPid, int stdinFd, int stdoutFd, int stderrFd)

Identical to Spawn.asyncWithPipes but instead of creating pipes for the stdin/stdout/stderr, you can pass existing file descriptors into this function through the stdin_fd, stdout_fd and stderr_fd parameters. The following flags also have their behaviour slightly tweaked as a result:

checkExitStatus
bool checkExitStatus(int exitStatus)

Set error if exit_status indicates the child exited abnormally (e.g. with a nonzero exit code, or via a fatal signal).

closePid
void closePid(GPid pid)

On some platforms, notably Windows, the GPid type represents a resource which must be closed to prevent resource leaking. Spawn.closePid is provided for this purpose. It should be used on all platforms, even though it doesn't do anything under UNIX.

commandLineAsync
bool commandLineAsync(string commandLine)

A simple version of Spawn.async that parses a command line with g_shell_parse_argv() and passes it to Spawn.async. Runs a command line in the background. Unlike Spawn.async, the G_SPAWN_SEARCH_PATH flag is enabled, other flags are not. Note that G_SPAWN_SEARCH_PATH can have security implications, so consider using Spawn.async directly if appropriate. Possible errors are those from g_shell_parse_argv() and Spawn.async.

commandLineSync
bool commandLineSync(string commandLine, string standardOutput, string standardError, int exitStatus)

A simple version of Spawn.sync with little-used parameters removed, taking a command line instead of an argument vector. See Spawn.sync for full details. command_line will be parsed by g_shell_parse_argv(). Unlike Spawn.sync, the G_SPAWN_SEARCH_PATH flag is enabled. Note that G_SPAWN_SEARCH_PATH can have security implications, so consider using Spawn.sync directly if appropriate. Possible errors are those from Spawn.sync and those from g_shell_parse_argv().

errorQuark
GQuark errorQuark()
exitErrorQuark
GQuark exitErrorQuark()
sync
bool sync(string workingDirectory, string[] argv, string[] envp, GSpawnFlags flags, GSpawnChildSetupFunc childSetup, void* userData, string standardOutput, string standardError, int exitStatus)

Executes a child synchronously (waits for the child to exit before returning). All output from the child is stored in standard_output and standard_error, if those parameters are non-NULL. Note that you must set the G_SPAWN_STDOUT_TO_DEV_NULL and G_SPAWN_STDERR_TO_DEV_NULL flags when passing NULL for standard_output and standard_error.