'connect shell adb with python
I am trying to access a device from adb but it keeps loading and does not access
function:
def get_device():
outuput = subprocess.Popen(["adb.exe" , "devices" , "-l" ] ,stdout=subprocess.PIPE)
outuput = str(outuput.communicate()[0])
devices = [x.split() for _ , x in enumerate(outuput.split("\\n")) if "model:" in x and not _ == 0 ]
return devices
I've tried this:
devices = get_device()[0]
adb_ouput = check_output(["adb", "-s" , devices, "shell"] , shell=True, text=True)
print(adb_ouput)
I also tried:
p = subprocess.Popen(["adb", "-s" , devices, "shell"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
print(out)
but it stays loading and does not continue
Solution 1:[1]
There are many libraries doing that as mentioned in comments. One of them is AndroidViewClient/culebra.
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
from com.dtmilano.android.viewclient import ViewClient
device, serialno = ViewClient.connectToDeviceOrExit()
print(device.shell('ls -l'))
Which does many other things as well which you may need after doing the simple steps you have tried.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Diego Torres Milano |
