美文网首页
differents between os.system() &

differents between os.system() &

作者: 沉沙某人 | 来源:发表于2017-06-13 16:53 被阅读0次

    example:


    Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit (AMD64)] on win32Type "help", "copyright", "credits" or "license" for more information.

    >>> import os

    >>> cmd = 'adb devices'

    >>> dis1 = os.system(cmd)

    List of devices attached

    HEE6R15617005387        device

    >>> dis1

    0

    >>> dis2 = os.popen(cmd)

    >>> dis2

    <open file 'adb devices', mode 'r' at 0x00000000024AC150>

    >>> dis2.read()

    'List of devices attached\nHEE6R15617005387\tdevice\n\n'

    >>>


    由此可见:

    os.system(cmd)  # os.system() 屏幕输出无法捕获

    display = os.popen(cmd)   #os.popen()输出可捕获成文件

    相关文章

      网友评论

          本文标题:differents between os.system() &

          本文链接:https://www.haomeiwen.com/subject/taadqxtx.html