python自动获取多个adb设备名
import os
def check_adb_devices():
'''
检查adb 设备,并返回设备sn list
:return: 设备sn list
'''
adb_list=[]
ret =os.popen('adb devices').readlines()
print('ret={}'.format(ret))
if len(ret) ==1:
print('未识别到adb 设备...')
return adb_list
else:
for n in ret:
if '\tdevice\n' in n:
adb=str(n).strip().split('\tdevice')[0].strip()
adb_list.append(str(adb))
print('adb设备数量={},adb_list={}'.format(len(adb_list), adb_list))
return adb_list
if __name__ == '__main__':
check_adb_devices()
执行结果:
ret=['List of devices attached\n', '1234a4f3\tdevice\n', 'mn4xwsbfrd\tdevice\n', '\n']
adb设备数量=2,adb_list=['1234a4f3', 'mn4xwsbfrd']
|