
我是stackoverflow的初学者,所以我无法添加评论.
我看到了此页面:
Read command output inside su process
我尝试了这个答案,没关系:
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 permissionsstdin.writeBytes("ls /data\n"); // \n executes the commandinputStream 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中尝试命令时,响应是相同的命令.
我输入以下命令:
stdin.writeBytes("echo AT+CQI?\n");答案是:
AT+CQI?我写:
stdin.writeBytes("echo ATinkd\n");答案是:
ATinkd那就是“ bla..bla..bla ..”.这意味着androID系统无法将此命令识别为at命令.
我想知道是否有人建议或解决方案.
解决方法:
首先,我认为您只是向外壳中的stdout发送了AT命令,除了给您回读的回声外,它什么也不会做.为了使这种方法起作用,您必须将echo命令重定向到串行端口设备文件. AndroID手机为此使用各种设备,/ dev / ttyGS0和/ dev / smd0似乎是通用名称.
但是,我建议使用程序atinput发送AT命令并捕获调制解调器响应.它是专门为从命令行这样使用而编写的.这将使您免于直接与调制解调器通信,剩下的就是管道处理读取的响应.
总结以上是内存溢出为你收集整理的在root机器人上执行at命令并获取结果全部内容,希望文章能够帮你解决在root机器人上执行at命令并获取结果所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)