differents between os.system() &

2017-06-13  本文已影响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()输出可捕获成文件

上一篇下一篇

猜你喜欢

热点阅读