将Shell ADB与Python连接

发布于 2025-01-20 07:48:23 字数 709 浏览 2 评论 0原文

我正在尝试从ADB访问设备,但它一直在加载且无法访问

功能:

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

我尝试了:

devices = get_device()[0]
adb_ouput = check_output(["adb", "-s" , devices, "shell"] , shell=True, text=True)
print(adb_ouput)

我也尝试过:

p = subprocess.Popen(["adb", "-s" , devices, "shell"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
print(out)

但是它保持了加载,并且不会继续

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感情废物 2025-01-27 07:48:23

如评论中提到的那样,有许多库这样做。其中之一是 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'))

在执行了尝试的简单步骤之后,您可能还需要许多其他事情。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文