用于将 AT 命令发送到调制解调器的 ADB shell 脚本 - 无法将控制权返回到 shell 并捕获输出
我已经发布了类似的问题,但仍然无法完成我的工作,所以这是第二次尝试,其中 我想更清楚地说明我的绊脚石。
所以基本上我在Android手机的adb shell中,通过发送AT命令与GPRS调制解调器通信。 我可以通过将 at 命令重定向到代表调制解调器的设备文件来完成此操作;我可以回读 使用在后台运行的 cat 实用程序进行响应(较早开始)。我在脚本中实现了它 它可以发送单个 AT 命令并读回响应。例如,这是一个脚本 发送至+警察?获取手机所在运营商的名称:
#SendATCommand script
cat /dev/pts/7 &
echo -e at+cops?\\r > /dev/pts/7
输出如下:
# ./sendATCommand
./sendATCommand
#
+COPS: 0,0,"AT&T",6
OK
/dev/pts/7: invalid length
现在有两个我无法解决的问题:
- 我仍然需要手动按 ENTER 按钮才能返回 adb shell 提示符“#”。有办法返回吗 以编程方式显示“#”提示符?再次,我处于 adb shell 中。
- 显示的响应无法捕获,无论是在变量中,还是在文件中,(例如(#./sendATCommand>output.txt)Output.txt文件将为空。我尝试了各种重定向,但仍然没有得到它 谁能帮我
解决这两个问题(如果可能的话)? 从我的 Android 设备所在的 PC 上运行的“超级”脚本(例如 Perl 或 Powershell)调用 已连接,但在解决这两个问题之前没有办法做到这一点。预先非常感谢!
I already posted similar question, but still could not get my job done, so this a a second attempt, where
I would like to more clearly state my stumbling block.
So basically I am in Android phone's adb shell, communicating with the GPRS modem by sending AT commands.
I am able to do it by redirecting at command to the device file representing the modem; and I can read back
the response using cat utility running on the background (started earlier). I implemented it in a script
which can send a single AT command and read back the response. For example, here is the script to
send at+cops? to get the name of the operator the mobile is camping on:
#SendATCommand script
cat /dev/pts/7 &
echo -e at+cops?\\r > /dev/pts/7
The output looks as follows:
# ./sendATCommand
./sendATCommand
#
+COPS: 0,0,"AT&T",6
OK
/dev/pts/7: invalid length
Now here are two problems which I cannot resolve:
- I still need to manually press ENTER button to get back adb shell prompt "#". Is there a way to return
to "#" prompt programmatically? Again, I am in adb shell. - The displayed response cannot be captured, neither in a variable, nor in file, (such as(#./sendATCommand > output.txt) Output.txt file will be empty. I tried various redirections, but still did not get it to work.
Can anyone please help me resolve those two problems (if ever possible)? Ultimately I want this little script to be
called from a "super" script (e.g. Perl or Powershell) running on PC to which my Android device is
connected, but there is no way to do it until those two problems resolved. Thanks a lot in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议您尝试我的 atinout 程序,它应该正是您所要求的:一个发送 AT 的程序来自命令行的命令并捕获输出。
在您的情况下,结果应该类似于
并且要捕获输出,只需输入文件名而不是最后一个
-
。I suggest that you try out my atinout program which should be exactly what you are asking for: a program to send AT commands from the command line and capture the output.
In your case the result should be like
and to capture the output just put a file name instead of the last
-
.我在将输出重定向到文件时遇到了类似的问题。我通过在 echo 命令前面添加 CMD /c 解决了我的问题。也就是说,如果我理解正确,您需要告诉系统它需要等到命令完成执行,然后才将输出重定向到文件。我是在DOS下做的。
由于您在 ANDROID 上运行,请尝试在命令前面添加 sh -c 。希望有帮助。
I had similar problems with redirecting output to file. I resolved my problem by adding CMD /c in front of the echo command. I.e. if I understand correctly you need to tell the system that it needs to wait until command finishes executing and only then redirect output to a file. I was doing it in DOS.
Since you are running on ANDROID try adding sh -c in front of your command. Hope it helps.