python中os.system()的返回值
2010-09-07 17:25
274 查看
记得老早的时候python.cn邮件列表上有朋友问过os.system()的返回值异常的问题。今天又碰到啦,所以总结下。
问题:
/bin/xxx.py是一个返回码为1的程序。
当python 程序使用os.system(”./bin/xxx.py”) 这样调用的时候, 成功运行后os.system
的返回值出现了问题,变成了256 ,也就是0×100。而不是正常应该返回的1。
解决:
查阅了文档发现
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的返回值并不是执行程序的返回结果。而是一个16位的数,它的高位才是返回码。也就是说os.system()返回256即
0×0100,返回码应该是其高位0×01即1。
问题:
/bin/xxx.py是一个返回码为1的程序。
当python 程序使用os.system(”./bin/xxx.py”) 这样调用的时候, 成功运行后os.system
的返回值出现了问题,变成了256 ,也就是0×100。而不是正常应该返回的1。
解决:
查阅了文档发现
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的返回值并不是执行程序的返回结果。而是一个16位的数,它的高位才是返回码。也就是说os.system()返回256即
0×0100,返回码应该是其高位0×01即1。
相关文章推荐
- 32位python的bug:os.system返回码一直为0
- Python中os.system()的返回值
- python中os.system()的返回值
- python中os.system()的返回值
- python中os.system()的返回值
- Python执行shell脚本的几种方式(最好用subprocess.Popen来替代os.system)
- python调用Shell脚本:os.system(cmd)或os.popen(cmd)
- Python执行系统命令的方法 os.system(),os.popen(),commands
- [转]Python执行系统命令的方法 os.system(),os.popen(),commands
- Python_cmd的各种实现方法及优劣(subprocess.Popen, os.system和commands.getstatusoutput)
- python中那纠结的os.system()与空格处理
- Python执行cmd的各种实现方法及优劣(subprocess.Popen, os.system和commands.getstatusoutput)
- python调用Shell脚本:os.system(cmd)或os.popen(cmd),
- Python执行系统命令的方法 os.system(),os.popen(),commands
- python os.system重定向stdout到变量 ,同时获取返回值
- python调用Shell脚本:os.system(cmd)或os.popen(cmd)
- Python执行系统命令,os.system && os.popen && subprocess.Popen
- python os.system()和os.popen()
- 实用的 Python —— os.system() 在 python 语句中执行 dos 命令
- python调用Shell脚本:os.system(cmd)或os.popen(cmd)的区别