1ysc3839 205 天前 via Android ♥ 1
先查 Python 文档 https://docs.python.org/2/library/commands.html#commands.getstatusoutput
有写 The exit status for the command can be interpreted according to the rules for the C function wait().
再查 Linux man https://linux.die.net/man/2/wait
If status is not NULL, wait() and waitpid() store status information in the int to which it points. This integer can be inspected with the following macros (which take the integer itself as an argument, not a pointer to it, as is done in wait() and waitpid()!):
returns the exit status of the child. This consists of the least significant 8 bits of the status argument that the child specified in a call to exit(3) or _exit(2) or as the argument for a return statement in main(). This macro should only be employed if WIFEXITED returned true.
3ysc3839 205 天前 via Android ♥ 1
@shenxgan 先用 WIFEXITED 判断是否是正常退出，是的话用 WEXITSTATUS 获取返回值。
Python 有内置这两个函数 https://docs.python.org/2/library/os.html#os.WIFEXITED