最佳答案
os.system
的返回值依赖于操作系统。
在 Unix 上,返回值是一个 16 位数字,其中包含两条不同的信息。来自文档:
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)
因此,如果信号编号(低字节)为 0,理论上,将结果移位 8 位(result >> 8
)以获得错误代码是安全的。函数os.WEXITSTATUS
正是这样做的。如果错误码为0,则通常表示进程无错误退出。
在 Windows 上,文档指定 os.system
的返回值取决于 shell。如果shell是cmd.exe
(默认),则值为进程的返回码。同样,0 表示没有错误。
对于其他错误代码:
关于python - Python 中 os.system() 的返回值是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6466711/