如何使用python打开adb shell并在shell中执行命令 [英] How to open adb shell and execute commands inside shell using python
问题描述
我正在尝试使用subprocess.Popen在python中执行adb shell命令。
示例:需要在adb shell中执行命令。手动执行时,我打开命令窗口并按如下所示执行它。
> adb shell
# < command>
在Python中,我正在使用以下方法,但是过程卡住了,没有给出输出
子进程.Popen('adb shell< command>)
尝试在命令窗口中手动执行,结果与python代码相同,卡住并且不提供输出
> adb shell< command>
我正在尝试在后台执行二进制文件(使用二进制文件名,后跟&)命令。
找到了一种在子流程模块中使用communication()方法做到这一点的方法
procId = subprocess.Popen('adb shell',stdin = subprocess.PIPE)
procId.communicate('command1\ncommand2\nexit\n' )
I am trying to execute adb shell commands in python using subprocess.Popen
Example: Need to execute 'command' in adb shell. While executing manually, I open the command window and execute as below and it works.
>adb shell
#<command>
In Python I am using as below but the process is stuck and doesn't give output
subprocess.Popen('adb shell <command>)
Tried executing manually in command window, same result as python code,stuck and doesn't give output
>adb shell <command>
I am trying to execute a binary file in background(using binary file name followed by &) in the command.
Found a way to do it using communicate() method in subprocess module
procId = subprocess.Popen('adb shell', stdin = subprocess.PIPE)
procId.communicate('command1\ncommand2\nexit\n')
这篇关于如何使用python打开adb shell并在shell中执行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!