python中os.system.获取输出信息_python中os.system()的返回值
[python中os.system()的返回值]
如果第三方程序返回的是布爾型返回值,os.system會(huì)將true轉(zhuǎn)為1,false轉(zhuǎn)為0進(jìn)行返回。
問題:
/bin/xxx.py是一個(gè)返回碼為1的程序。
當(dāng)python 程序使用os.system(”./bin/xxx.py”) 這樣調(diào)用的時(shí)候, 成功運(yùn)行后os.system 的返回值出現(xiàn)了問題,變成了256 ,也就是0×100。而不是正常應(yīng)該返回的1。
解決:
查閱了文檔發(fā)現(xiàn)
os.system()的返回為:
On Unix, the return value is the exit status of the process encoded in the format specified for wait().
而os.wait()的返回為:
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);
os.system的返回值并不是執(zhí)行程序的返回結(jié)果。而是一個(gè)16位的數(shù),它的高位才是返回碼。也就是說os.system()返回256即 0×0100,返回碼應(yīng)該是其高位0×01即1。
與50位技術(shù)專家面對(duì)面20年技術(shù)見證,附贈(zèng)技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的python中os.system.获取输出信息_python中os.system()的返回值的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python统计图原理_AB测试原理及样
- 下一篇: python vs java 搞笑视频_