check_wait_status


Description:

[ Version ( since = "2.70" ) ]
[ CCode ( cname = "g_spawn_check_wait_status" ) ]
public bool check_wait_status (int wait_status) throws Error

Set throws if wait_status indicates the child exited abnormally (e.

g. with a nonzero exit code, or via a fatal signal).

The spawn_sync and g_child_watch_add family of APIs return the status of subprocesses encoded in a platform-specific way. On Unix, this is guaranteed to be in the same format waitpid 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 wait_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 Error or print a message to standard error. In that common case, this function can be used. Note that the error message in throws will contain human-readable information about the wait status.

The domain and code of throws 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 if_exited would be true of wait_status. On Windows, it is always the case.

The special semantics are that the actual exit code will be the code set in throws, 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 (for example if it was killed by a signal), 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 if_exited and exit_status on wait_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.

Prior to version 2.70, check_exit_status provides the same functionality, although under a misleading name.

Parameters:

wait_status

A platform-specific wait status as returned from spawn_sync

Returns:

true if child exited successfully, false otherwise (and throws will be set)


Namespace: GLib.Process
Package: glib-2.0