Python调用adb命令实现对多台设备同时进行reboot的方法

(编辑:jimmy 日期: 2024/9/29 浏览:2)

首先,adb实现对设备的reboot命令是:adb reboot . 但是如果是两台/多台设备的时候,需要声明serial number: adb -s serial_no reboot.

那么,如何用python实现对多台设备进行adb操作呢(reboot)"htmlcode">

import subprocess

adb device 获取所有设备的 serial number:

devices = subprocess.Popen(
 'adb devices'.split(),
 stdout=subprocess.PIPE,
 stderr=subprocess.PIPE
).communicate()[0]

这样adb device命令的返回信息都在devices下,但是我们只需要 serial number的:

serial_nos = []
for item in devices.split():
 filters = ['list', 'of', 'device', 'devices', 'attached']
 if item.lower() not in filters:
  serial_nos.append(item)

这样serial_nos 下保存的就是所有设备的 serial number 了,下面我们只需要依次对其进行adb -s [serial_number] reboot即可:

for serial_no in serial_nos:
 reboot_cmds.append('adb -s %s reboot' % serial_no)
for reboot_cmd in reboot_cmds:
 subprocess.Popen(
  reboot_cmd.split(),
  stdout=subprocess.PIPE,
  stderr=subprocess.PIPE
 ).communicate()[0]

这样,每个设备都进行了reboot的操作了……

以上这篇Python调用adb命令实现对多台设备同时进行reboot的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

一句话新闻

Windows上运行安卓你用过了吗
在去年的5月23日,借助Intel Bridge Technology以及Intel Celadon两项技术的驱动,Intel为PC用户带来了Android On Windows(AOW)平台,并携手国内软件公司腾讯共同推出了腾讯应用宝电脑版,将Windows与安卓两大生态进行了融合,PC的使用体验随即被带入到了一个全新的阶段。