[英]how can i passs input in adb shell using python script?
I am facing a problem, have to pass an input after I run command: adb shell libtest_ip through python:我遇到了一个问题,在运行命令后必须传递一个输入:adb shell libtest_ip 到 python:
import subprocess
command = 'adb shell libtest_ip'
p = subprocess.Popen(command, shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
after this I have to pass input like 1 or en_us etc.. but as soon as the command to sun binary(libtest_ip is a binary), is executed, it gets stuck.在此之后,我必须传递 1 或 en_us 等输入。但是一旦执行 sun 二进制命令(libtest_ip 是二进制文件),它就会卡住。
Please help me if anyone have idea how to solve this?如果有人知道如何解决这个问题,请帮助我?
I think your best bet is pexpect .我认为你最好的选择是pexpect 。 Specially you can take a look at script.py that would help you creating the interactive script.
特别是您可以查看script.py ,它可以帮助您创建交互式脚本。
Basically, you should end up with something like this基本上,你应该得到这样的结果
...
self.child.expect('Whatever')
self.child.sendline('1')
self.child.expect('Whatever 2')
self.child.sendline('en-us')
...
Your example should work, try你的例子应该工作,试试
#! /usr/bin/env python3
import pexpect
print(pexpect.run('/bin/echo hello'))
and running it should output并运行它应该 output
% ./test-pexpect.py
b'hello\r\n'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.