在 root 的 android 上执行 at 命令并得到结果 [英] implement at command on rooted android and get the result

查看:34
本文介绍了在 root 的 android 上执行 at 命令并得到结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 stackoverflow 的初学者,所以无法添加评论.

I'm a beginner in stackoverflow so I cant add a comment.

我看到了这个页面:
读取su进程内的命令输出

我试过这个答案,没问题:

and I tried this answer and it is ok:

Process p = Runtime.getRuntime().exec(new String[]{"su", "-c", "system/bin/sh"});
DataOutputStream stdin = new DataOutputStream(p.getOutputStream());
//from here all commands are executed with su permissions
stdin.writeBytes("ls /data
"); // 
 executes the command
InputStream stdout = p.getInputStream();
byte[] buffer = new byte[BUFF_LEN];
int read;
String out = new String();
//read method will wait forever if there is nothing in the stream
//so we need to read it in another way than while((read=stdout.read(buffer))>0)
while(true){
    read = stdout.read(buffer);
    out += new String(buffer, 0, read);
    if(read<BUFF_LEN){
        //we have read everything
        break;
       }
 }
 //do something with the output

但是当我在 shell 中尝试 at 命令时,响应是相同的命令.

but when I tried at command in the shell the response was the same command.

我把这个命令:

stdin.writeBytes("echo AT+CQI?
");

答案是:

AT+CQI?

我写道:

stdin.writeBytes("echo ATinkd
");

答案是:

ATinkd

意思是bla..bla..bla..".这意味着 android 系统无法像 at 命令那样识别此命令.

That is mean "bla..bla..bla..". that is mean the android system does not recognize this commands as at commands.

我想知道是否有人有建议或解决方案.

I wonder if any body have an advice or solution.

推荐答案

首先,我认为您只是将 AT 命令发送到 shell 中的 stdout,除了给您回读的回声之外,它不会做任何事情.要使这种方法起作用,您必须将 echo 命令重定向到串行端口设备文件.Android 手机为此使用各种设备,/dev/ttyGS0/dev/smd0 似乎是通用名称.

First I think you are just sending the AT command to stdout in the shell which will not do anything other than giving you an echo which you read back. For this approach to work you have to redirect the echo command to the serial port device file. Android phones use various devices for this, /dev/ttyGS0 and /dev/smd0 seems to be common names.

不过,我建议使用 atinput 程序来发送 AT 命令并捕获调制解调器响应.它是专门编写的,可以像这样从命令行使用.这将使您免于直接与调制解调器通信,剩下的唯一事情就是处理读取响应的管道.

However I would suggest using the program atinput to send AT commands and capture modem responses. It is specifically written to be used from the command line like that. That will relieve you from communicating directly with the modem and the only thing left is the pipe handling reading the response.

这篇关于在 root 的 android 上执行 at 命令并得到结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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