python中os.system()和os.popen()的返回值
来源:互联网 发布:西安财经行知学院饭堂 编辑:程序博客网 时间:2024/06/05 02:02
python中os.system()的返回值
记得老早的时候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。
参照http://skynjl.blog.163.com/blog/static/603053922009127102056309/
python中os.pepen()的返回值
#!/usr/bin/pythonimport osimport rep=os.popen('ssh 10.3.16.121 ps aux | grep mysql')#print px=p.read()print xp.close()
- python中os.system()和os.popen()的返回值
- python中os.system、os.popen、subprocess.popen的区别
- python中os.popen, os.system()区别
- python os.system()和os.popen()
- python os.popen()和os.system()区别
- os.system() 和os.popen()的区别
- python os.popen os.system
- python中os.system()的返回值
- Python中os.system()的返回值
- python中os.system()的返回值
- python中os.system()的返回值
- python中os.system()的返回值
- python中os.system()的返回值
- python中os.system()的返回值
- python中os.system()的返回值
- 关于python中os.system,os.popen,os.comands
- Python中 os.system()与os.popen()
- python中os.popen, os.system()区别(转自:ccorz)
- 【asp.net】代码中尖括号和百分号的含义
- 通过/etc/inittab文件进行初始化
- 使用Visual Studio Development Server开发域验证程序时出现HTTP Error 403 - Forbidden错误的解决办法
- .NET程序员常用类库总结
- 五大最受欢迎的BUG管理系统
- python中os.system()和os.popen()的返回值
- Could not obtain an exclusive lock to the embedded LDAP data files
- (转)编写高性能 Web 应用程序的 10 个技巧 转自微软资料
- ASP.NET常用的类
- 富人与穷人的不同
- LVS大全
- Tags From Sina Micro-Blog
- 实用SQL語句
- 在C#中枚举的作用(enum)