spawn_async


Description:

public bool spawn_async (string? working_directory, string[] argv, string[]? envp, SpawnFlags _flags, SpawnChildSetupFunc? child_setup, out Pid child_pid) throws SpawnError

Executes a child program asynchronously.

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

You should call close_pid on the returned child process reference when you don't need it any more.

If you are writing a GTK application, and the program you are spawning is a graphical application too, then to ensure that the spawned program opens its windows on the right screen, you may want to use GdkAppLaunchContext, GAppLaunchContext, or set the display environment variable.

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.

Example: Spawn, async:

public static int main (string[] args) {
MainLoop loop = new MainLoop ();
try {
string[] spawn_args = {"ls", "-l", "-h"};
string[] spawn_env = Environ.get ();
Pid child_pid;

Process.spawn_async ("/",
spawn_args,
spawn_env,
SpawnFlags.SEARCH_PATH | SpawnFlags.DO_NOT_REAP_CHILD,
null,
out child_pid);

ChildWatch.add (child_pid, (pid, status) => {
// Triggered when the child indicated by child_pid exits
Process.close_pid (pid);
loop.quit ();
});

loop.run ();
} catch (SpawnError e) {
print ("Error: %s\n", e.message);
}
return 0;
}

valac --pkg glib-2.0 GLib.Process.spawn_async.vala

Parameters:

working_directory

child's current working directory, or null to inherit parent's

argv

child's argument vector

envp

child's environment, or null to inherit parent's

child_setup

function to run in the child just before `exec()`

child_pid

return location for child process reference, or null

flags

flags from SpawnFlags

user_data

user data for child_setup

Returns:

true on success, false if error is set


Namespace: GLib.Process
Package: glib-2.0