python中os.popen, os.system()区别

os.system的结果只是命令执行结果的返回值,执行成功为0:

>>> a=os.system('adb devices')
>>> a
0

可以看到,a为0

但用os.popen就可以读出执行的内容,popen返回的是file read的对象,对其进行读取使用read(),就可看到执行的输出:
    
>>> b=os.popen('adb devices')
>>> b.read()
'List of devices attached\nSNMBB18417516563\tdevice\nUYT0218209004285\tdevice\n\n'

可以看出,输出的结果比较特殊,带换行符\n

 

posted @ 2019-07-18 18:27  Golover  阅读(3698)  评论(0编辑  收藏  举报