Python calls the ADB command to implement reboot for multiple devices at the same time
First, ADB's reboot command for devices is: ADB reboot. However, if it is two/more devices, you need to declare serial number:adb-s Serial_no reboot.
So how do you use Python to implement ADB operations on multiple devices (reboot)?
This involves the use of the Python subprocess model:
Import subprocess
ADB device gets serial number for all devices:
devices = subprocess. Popen (
' adb devices '. Split (),
stdout=subprocess. PIPE,
stderr=subprocess. PIPE
). Communicate () [0]
So the return information for the ADB device command is under devices, but we only need serial number:
Serial_nos = [] for
the item in Devices.split ():
filters = [' list ', ' of ', ' device ', ' devices ', ' attached ']
if Item . Lower () Not in filters:
serial_nos.append (item)
So the Serial_nos save is all the serial number of the device, we only need to adb-s it in turn [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]
In this way, each device has a reboot operation ...
Here to introduce subprocess Model:python subprocess learning