在命令落实植根Android和得到的结果命令、结果、Android

2023-09-07 14:38:52 作者:动了情

我在计算器初学者,所以我不能添加评论。

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

我看到这个页面: 阅读苏流程内部命令输出

I saw this page: Read command output inside su process

和我想这个答案,这是确定的:

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\n"); // \n 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试图在命令的响应是相同的命令。

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

我把这个命令:

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

答案是:

AT+CQI?

我写的:

stdin.writeBytes("echo ATinkd\n");

答案是:

ATinkd

这是平均bla..bla..bla ..。这是指截至命令android系统无法识别该命令。

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命令到标准输出中,不会做任何事情比给你,你读回的回声等的外壳。对于这种方法来工作,你必须给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.

 
精彩推荐