python adb指令 adb shell
时间: 2024-01-30 14:12:14 浏览: 266
appium+python adb常用命令分享
以下是使用Python调用adb shell执行adb指令的示例:
```python
import subprocess
def run_adb_command(command):
adb_command = ['adb', 'shell'] + command.split()
result = subprocess.run(adb_command, capture_output=True, text=True)
return result.stdout.strip()
# 示例:获取设备连接状态
devices_output = run_adb_command('adb devices')
print(devices_output)
# 示例:控制Android设备输入
input_command = 'input text "Hello World"'
input_output = run_adb_command(input_command)
print(input_output)
# 示例:控制Android设备输出
output_command = 'echo "Hello World"'
output_output = run_adb_command(output_command)
print(output_output)
```
请注意,执行adb指令需要确保adb已经正确安装并且adb所在目录已经添加至PATH环境变量中。
阅读全文