Spawn

class Spawn {}

Constructors

this
this(string program, string[] envp)

Creates a Spawn for execution.

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

Creates a Spawn for execution.

Members

Aliases

ChildWatch
alias ChildWatch = bool delegate(Spawn)
Undocumented in source.
splitlines
alias splitlines = splitLines
Undocumented in source.
splitlines
alias splitlines = splitLines
Undocumented in source.

Classes

ReadFile
class ReadFile
Undocumented in source.

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

endOfError
bool endOfError()
Undocumented in source. Be warned that the author may not have intended to support it.
endOfOutput
bool endOfOutput()
Undocumented in source. Be warned that the author may not have intended to support it.
execAsyncWithPipes
int execAsyncWithPipes(ChildWatch externalWatch, bool delegate(string) readOutput, bool delegate(string) readError)

Executes the prepared process

getErrorString
string getErrorString()
Undocumented in source. Be warned that the author may not have intended to support it.
getExitStatus
int getExitStatus()
Undocumented in source. Be warned that the author may not have intended to support it.
getLastError
string getLastError()

Gets the last error message

getOutputString
string getOutputString()
Undocumented in source. Be warned that the author may not have intended to support it.

Static functions

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

See g_spawn_async_with_pipes() for a full description; this function simply calls the g_spawn_async_with_pipes() without any pipes. You should call g_spawn_close_pid() on the returned child process reference when you don't need it any more. Note If you are writing a GTK+ application, and the program you are spawning is a graphical application, too, then you may want to use gdk_spawn_on_screen() instead to ensure that the spawned program opens its windows on the right screen. Note Note that the returned child_pid on Windows is a handle to the child process and not its identifier. Process handles and process identifiers are different concepts on Windows.

checkExitStatus
int 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). The g_spawn_sync() and g_child_watch_add() family of APIs return an exit status for subprocesses encoded in a platform-specific way. On Unix, this is guaranteed to be in the same format waitpid(2) returns, and on Windows it is guaranteed to be the result of GetExitCodeProcess(). Prior to the introduction of this function in GLib 2.34, interpreting exit_status required use of platform-specific APIs, which is problematic for software using GLib as a cross-platform layer. Additionally, many programs simply want to determine whether or not the child exited successfully, and either propagate a GError or print a message to standard error. In that common case, this function can be used. Note that the error message in error will contain human-readable information about the exit status. The domain and code of error have special semantics in the case where the process has an "exit code", as opposed to being killed by a signal. On Unix, this happens if WIFEXITED would be true of exit_status. On Windows, it is always the case. The special semantics are that the actual exit code will be the code set in error, and the domain will be G_SPAWN_EXIT_ERROR. This allows you to differentiate between different exit codes. If the process was terminated by some means other than an exit status, the domain will be G_SPAWN_ERROR, and the code will be G_SPAWN_ERROR_FAILED. This function just offers convenience; you can of course also check the available platform via a macro such as G_OS_UNIX, and use WIFEXITED() and WEXITSTATUS() on exit_status directly. Do not attempt to scan or parse the error message string; it may be translated and/or change in future versions of GLib. Since 2.34

childWatchCallback
void childWatchCallback(int pid, int status, Spawn spawn)
Undocumented in source. Be warned that the author may not have intended to support it.
closePid
void closePid(GPid pid)

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

commandLineAsync
int commandLineAsync(string commandLine)

A simple version of g_spawn_async() that parses a command line with g_shell_parse_argv() and passes it to g_spawn_async(). Runs a command line in the background. Unlike g_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 g_spawn_async() directly if appropriate. Possible errors are those from g_shell_parse_argv() and g_spawn_async(). The same concerns on Windows apply as for g_spawn_command_line_sync().

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

A simple version of g_spawn_sync() with little-used parameters removed, taking a command line instead of an argument vector. See g_spawn_sync() for full details. command_line will be parsed by g_shell_parse_argv(). Unlike g_spawn_sync(), the G_SPAWN_SEARCH_PATH flag is enabled. Note that G_SPAWN_SEARCH_PATH can have security implications, so consider using g_spawn_sync() directly if appropriate. Possible errors are those from g_spawn_sync() and those from g_shell_parse_argv(). If exit_status is non-NULL, the platform-specific exit status of the child is stored there; see the documentation of g_spawn_check_exit_status() for how to use and interpret this. On Windows, please note the implications of g_shell_parse_argv() parsing command_line. Parsing is done according to Unix shell rules, not Windows command interpreter rules. Space is a separator, and backslashes are special. Thus you cannot simply pass a command_line containing canonical Windows paths, like "c:\\program files\\app\\app.exe", as the backslashes will be eaten, and the space will act as a separator. You need to enclose such paths with single quotes, like "'c:\\program files\\app\\app.exe' 'e:\\folder\\argument.txt'".

sync
int 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. If exit_status is non-NULL, the platform-specific exit status of the child is stored there; see the documentation of g_spawn_check_exit_status() for how to use and interpret this. Note that it is invalid to pass G_SPAWN_DO_NOT_REAP_CHILD in flags. If an error occurs, no data is returned in standard_output, standard_error, or exit_status. This function calls g_spawn_async_with_pipes() internally; see that function for full details on the other parameters and details on how these functions work on Windows.

Variables

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

Meta