File: exit_code.adoc

package info (click to toggle)
boost1.90 1.90.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 593,120 kB
  • sloc: cpp: 4,190,908; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,774; makefile: 1,161; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (43 lines) | stat: -rw-r--r-- 1,234 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
== `exit_code.hpp`
[#exit_code]

The exit code header provides portable handles for exit codes.

[source,cpp]
----
// The native exit-code type, usually an integral value
/* The OS may have a value different from `int` to represent
 * the exit codes of subprocesses. It might also
 * contain additional information.
 */
typedef implementation_defined native_exit_code_type;


// Check if the native exit code indicates the process is still running
bool process_is_running(native_exit_code_type code);

// Obtain the portable part of the exit code, i.e. what the subprocess has returned from main.
int evaluate_exit_code(native_exit_code_type code);

// Helper to subsume an exit-code into an error_code if there's no actual error isn't set.
error_code check_exit_code(
    error_code &ec, native_exit_code_type native_code,
    const error_category & category = error::get_exit_code_category());
----


The `check_exit_code` can be used like this:

[source,cpp]
----

process proc{co_await this_coro::executor, "exit", {"1"}};

co_await proc.async_wait(
    asio::deferred(
     [&proc](error_code ec, int)
     {
       return asio::deferred.values(
                 check_exit_code(ec, proc.native_exit_code())
             );
----