The return value of os.system
is OS-dependant.
On Unix, the return value is a 16-bit number that contains two different pieces of information. From the documentation:
a 16-bit number, whose low byte is the signal number that killed the process, and whose high byte is the exit status (if the signal number is zero)
So if the signal number (low byte) is 0, it would, in theory, be safe to shift the result by 8 bits (result >> 8
) to get the error code. The function os.WEXITSTATUS
does exactly this. If the error code is 0, that usually means that the process exited without errors.
On Windows, the documentation specifies that the return value of os.system
is shell-dependant. If the shell is cmd.exe
(the default one), the value is the return code of the process. Again, 0 would mean that there weren't errors.
For others error codes:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…