Exit Codes from system() not as expected

后端 未结 3 798
我在风中等你
我在风中等你 2021-01-18 19:27

The system() function seems to be returning 128 times the exit code I get from the process it\'s evoking.

From the man page:

RETURN VALUE

3条回答
  •  醉酒成梦
    2021-01-18 19:58

    Your citation of the system man page misses the relevant part:

    ... This latter return status is in the format specified in wait(2). Thus, the exit code of the command will be WEXITSTATUS(status).

    You need to right shift the return value by 8 (at least on Linux), to get the commands exit code.

    The portable approach is to just use the macro itself.

提交回复
热议问题