differents between os.system() & os.popen()

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()输出可捕获成文件

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容