Sch*_*hof 7 python command subprocess exit-code
在一个相关的问题中,我问到哪里可以找到C函数的文档"等待".这是尝试找出commands.getstatusoutput()模块的返回码.Stackoverflow通过,但文档没有帮助.这就是困扰我的:
#!/usr/bin/python
import commands
goodcommand = 'ls /'
badcommand = 'ls /fail'
status, output = commands.getstatusoutput(goodcommand)
print('Good command reported status of %s' % status)
status, output = commands.getstatusoutput(badcommand)
print('Bad command reported status of %s' % status)
Run Code Online (Sandbox Code Playgroud)
在OS X(Leopard)上运行时,我得到以下输出:(符合文档.)
$ python waitest.py
Good command reported status of 0
Bad command reported status of 256
Run Code Online (Sandbox Code Playgroud)
在OS X上,执行"ls/fail; echo $?" 得到以下输出:
$ ls /fail ; echo $?
ls: /fail: No such file or directory
1
Run Code Online (Sandbox Code Playgroud)
在Linux(Ubuntu Hardy)上运行时,我得到以下输出:
$ python waitest.py
Good command reported status of 0
Bad command reported status of 512
Run Code Online (Sandbox Code Playgroud)
在Ubuntu上,做"ls/fail"得到2:
$ ls /fail ; echo $?
ls: cannot access /fail: No such file or directory
2
Run Code Online (Sandbox Code Playgroud)
所以Python似乎将状态代码乘以256.嗯?这是在某处记录的吗?
| 归档时间: |
|
| 查看次数: |
15425 次 |
| 最近记录: |