spawn_sync


Description:

public bool spawn_sync (string? working_directory, string[] argv, string[]? envp, SpawnFlags _flags, SpawnChildSetupFunc? child_setup, out string standard_output = null, out string standard_error = null, out int exit_status = null) throws SpawnError

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 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, and on POSIX platforms, the same restrictions as for ChildWatchSource apply.

If an error occurs, no data is returned in standard_output, standard_error, or exit_status.

This function calls spawn_async_with_pipes internally; see that function for full details on the other parameters and details on how these functions work on Windows.

Example: Spawn, sync:

public static int main (string[] args) {
try {
string[] spawn_args = {"ls", "-l", "-h"};
string[] spawn_env = Environ.get ();
string ls_stdout;
string ls_stderr;
int ls_status;

Process.spawn_sync ("/",
spawn_args,
spawn_env,
SpawnFlags.SEARCH_PATH,
null,
out ls_stdout,
out ls_stderr,
out ls_status);

// Output: <File list>
print ("stdout:\n");
// Output: ````
print (ls_stdout);
print ("stderr:\n");
print (ls_stderr);
// Output: ``0``
print ("status: %d\n", ls_status);

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

return 0;
}

valac --pkg glib-2.0 GLib.Process.spawn_sync.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

standard_output

return location for child output, or null

standard_error

return location for child error messages, or null

exit_status

return location for child exit status, as returned by waitpid, or null

flags

flags from SpawnFlags

user_data

user data for child_setup

Returns:

true on success, false if an error was set


Namespace: GLib.Process
Package: glib-2.0