当前有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
>>>

相关文章:

  • 2021-11-20
  • 2021-12-16
  • 2021-11-20
  • 2021-07-21
  • 2022-12-23
  • 2021-11-20
  • 2022-12-23
猜你喜欢
  • 2021-11-13
  • 2022-12-23
  • 2021-10-27
  • 2021-11-20
  • 2022-12-23
  • 2022-02-11
  • 2022-01-04
相关资源
相似解决方案