os.system
这个命令只能简单粗暴的执行命令,想要,是不能获取到输出的。
os.popen
这个和打开文件有点像,执行命令,然后读出来。
例子
比如我这里连接了三个设备:
List of devices attached
3cdbd05d7cf5 device
3f33d62a7cf5 device
8212971d7ce5 device
现在要读取所有已经连接的android设备:
import re
import os
f = os.popen('adb devices', 'r')
s = f.read()
re.findall('(\w+)\s*device\s+', s)
# ['3cdbd05d7cf5', '3f33d62a7cf5', '8212971d7ce5']