亚行的shell脚本发送AT命令到调制解调器不能返回控制到外壳并捕获输出 [英] ADB shell script to send AT commands to a modem-cannot return control to a shell and capture output

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

问题描述

我已经张贴类似的问题,但还是没能得到我的工作做好,所以这个AA第二次尝试,其中, 我想更清楚地说明我的绊脚石。

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手机的亚行外壳,通过发送AT命令与GPRS调制解调器通信。 我可以通过在命令重定向到设备文件重新presenting调制解调器做到这一点;我可以读回 在后台运行的响应使用cat命令(起步较早)。我在脚本中实现它 它可以发送一个单一的AT命令和读回的响应。例如,下面是脚本 发送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

输出如下所示:

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:

  1. 在我还需要人工preSS ENTER键返回亚行的shell提示符#。有没有办法返回 以#提示符编程?同样,我在亚行的shell。
  2. 在显示的响应不能被捕获,既不是一个变量,也没有在文件中,(如(#。/ sendATCommand> output.txt的)Output.txt的文件是空的。我试过各种重定向,但仍没有得到它的工作。
  1. 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.
  2. 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.

任何人都可以请帮我解决这两个问题(如果有的话可能)?最后,我想这个脚本是 从超级脚本调用(如Perl或Powershell的)在PC到手机的Andr​​oid设备运行 连接,但没有办法做到这一点,直到这两个问题解决了。感谢很多提前!

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 解决我的问题。即如果我理解正确,你需要告诉它需要等到命令执行完毕,然后才将输出重定向到文件系统。我在做这在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.

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

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