zoukankan      html  css  js  c++  java
  • python中os.system()的返回值

    补充一句:如果第三方程序返回的是布尔型返回值,os.system会将true转为1,false转为0进行返回。

    下面是转发:

    记得老早的时候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。

  • 相关阅读:
    SharedPreferences介绍,用来做数据存储
    android中的回调简单认识
    git的使用
    Android Studio插件美化Android Studio,文艺清新范
    arp欺骗技术
    进程和线程的关系
    Win下常用命令大全
    JavaWeb系列之:Servlet
    JavaWeb系列之:监听器
    JavaWeb系列之:过滤器
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3067498.html
Copyright © 2011-2022 走看看