通过python检测当前adb是否能正常运行
可以通过以下代码来检测当前adb是否能正常运行:
import subprocess
def check_adb_connection():
# 执行adb devices命令
cmd = ["adb", "devices"]
try:
# 使用subprocess模块执行命令
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
# 检查输出结果中是否包含“List of devices attached”字符串,如果包含则表示adb连接正常
if "List of devices attached" in output.decode("utf-8"):
return True
else:
return False
except subprocess.CalledProcessError as e:
# 如果执行命令出现异常,则表示adb连接异常
return False
# 测试连接
if check_adb_connection():
print("ADB连接正常")
else:
print("ADB连接异常")
该代码会执行adb devices命令,并检查输出结果中是否包含“List of devices attached”字符串来判断是否连接正常。如果连接正常,则返回True,否则返回False
原文地址: https://www.cveoy.top/t/topic/fdv4 著作权归作者所有。请勿转载和采集!