spawn_sync
Description:
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 wait_status
is non-null, the platform-specific status of the child is stored there; see the
documentation of check_wait_status for how to use and interpret this.
On Unix platforms, note that it is usually not equal to the integer passed to `exit()` or returned from `main()`.
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 wait_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, which must be non-empty and null-terminated |
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 |
wait_status |
return location for child wait status, as returned by waitpid, or null |
flags |
flags from SpawnFlags |
user_data |
user data for |
Returns:
true on success, false if an error was set |