将 AT 命令发送到调制解调器的 ADB shell 脚本 - 无法将控制权返回给 shell 并捕获输出 [英] ADB shell script to send AT commands to a modem-cannot return control to a shell and capture output

查看:31
本文介绍了将 AT 命令发送到调制解调器的 ADB shell 脚本 - 无法将控制权返回给 shell 并捕获输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经发布了类似的问题,但仍然无法完成我的工作,所以这是第二次尝试,其中我想更清楚地说明我的绊脚石.

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.

所以基本上我在Android手机的adb shell中,通过发送AT命令与GPRS调制解调器通信.我可以通过将 at 命令重定向到代表调制解调器的设备文件来做到这一点;我可以回读使用在后台运行的 cat 实用程序的响应(较早开始).我在脚本中实现了它它可以发送单个 AT 命令并回读响应.例如,这里是脚本发送 + 警察?获取手机所在运营商的名称:

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

输出如下:

# ./sendATCommand 
./sendATCommand 
# 
+COPS: 0,0,"AT&T",6 

OK 
/dev/pts/7: invalid length 

现在有两个我无法解决的问题:

Now here are two problems which I cannot resolve:

  1. 我仍然需要手动按 ENTER 按钮才能返回 adb shell 提示#".有没有办法返回以编程方式#"提示?再次,我在 adb shell 中.
  2. 无法捕获显示的响应,无论是在变量中,还是在文件中,(例如(#./sendATCommand > output.txt) Output.txt 文件都会为空.我尝试了各种重定向,但仍然没有得到它工作.

谁能帮我解决这两个问题(如果可能的话)?最终我希望这个小脚本成为从我的 Android 设备所在的 PC 上运行的超级"脚本(例如 Perl 或 Powershell)调用连接,但在这两个问题解决之前没有办法做到这一点.非常感谢提前!

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!

推荐答案

我在将输出重定向到文件时遇到了类似的问题.我通过在 echo 命令前面添加 CMD/c 解决了我的问题.IE.如果我理解正确,您需要告诉系统它需要等到命令完成执行,然后才将输出重定向到文件.我是在DOS下做的.

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.

由于您在 ANDROID 上运行,请尝试在命令前添加 sh -c.希望能帮助到你.

Since you are running on ANDROID try adding sh -c in front of your command. Hope it helps.

这篇关于将 AT 命令发送到调制解调器的 ADB shell 脚本 - 无法将控制权返回给 shell 并捕获输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆