spawn_command_line_sync


Description:

public bool spawn_command_line_sync (string command_line, out string standard_output = null, out string standard_error = null, out int wait_status = null) throws SpawnError

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.

The command_line argument will be parsed by 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 parse_argv.

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()`.

On Windows, please note the implications of 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'".

Example: Spawn a command line, sync:

public static int main (string[] args) {
string ls_stdout;
string ls_stderr;
int ls_status;

try {
Process.spawn_command_line_sync ("ls",
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_command_line_sync.vala

Parameters:

command_line

a command line

standard_output

return location for child output

standard_error

return location for child errors

wait_status

return location for child wait status, as returned by waitpid

Returns:

true on success, false if an error was set


Namespace: GLib.Process
Package: glib-2.0