當前有shell個腳本/tmp/test.sh,內容如下:
#!/bin/bash
exit 11
使用Python的os.system調用,獲取返回值是:
>>> ret=os.system("/tmp/test.sh")
>>> ret
2816
查看Manual沒有說明。網上找到解釋如下:
os.system(cmd):
該方法在調用完shell腳本后,返回一個16位的二進制數,低位為殺死所調用腳本的信號號碼,高位為腳本的退出狀態碼。如果我們需要獲得os.system的正確返回值,那使用位移運算(或者除以256)可以還原返回值:
>>> ret/256
11
>>> ret>>8
11
>>>