android 调用外部命令的问题(Runtime.getRuntime().exec参数)
调用ls还有cat命名是没问题的,但是有些命令用不了,例如ll,打印显示环境有问题,不知道怎么解?
代码:
private String ssss() {
String TAG2 = "CMD";
try {
String cmd="ls";
Process process =Runtime.getRuntime().exec(cmd);
InputStream in1 = process.getInputStream();
BufferedReader reader1 = new BufferedReader(new InputStreamReader(in1));
String line1;
Log.i(TAG2, "返回结果" + reader1.readLine());
while ((line1 = reader1.readLine()) != null) {
Log.i(TAG2, "返回结果=" + line1);
}
in1.close();
} catch (IOException ex) {
ex.printStackTrace();
// result2 = "N/A";
}
return null;
}
String cmd="ls"打印结果:
644-644/com.example.MEM I/CMD﹕ 返回结果acct
03-23 16:42:56.157 644-644/com.example.MEM I/CMD﹕ 返回结果=config
03-23 16:42:56.157 644-644/com.example.MEM I/CMD﹕ 返回结果=d
03-23 16:42:56.157 644-644/com.example.MEM I/CMD﹕ 返回结果=default.prop
03-23 16:42:56.157 644-644/com.example.MEM I/CMD﹕ 返回结果=etc
03-23 16:42:56.157 644-644/com.example.MEM I/CMD﹕ 返回结果=init.goldfish.rc
03-23 16:42:56.157 644-644/com.example.MEM I/CMD﹕ 返回结果=init.recovery.sun7i.rc
03-23 16:42:56.157 644-644/com.example.MEM I/CMD﹕ 返回结果=init.sdb.rc
03-23 16:42:56.157 644-644/com.example.MEM I/CMD﹕ 返回结果=init.sdd.rc
03-23 16:42:56.157 644-644/com.example.MEM I/CMD﹕ 返回结果=init.sun7i.rc
03-23 16:42:56.157 644-644/com.example.MEM I/CMD﹕ 返回结果=init.trace.rc
03-23 16:42:56.157 644-644/com.example.MEM I/CMD﹕ 返回结果=initlogo.rle
03-23 16:42:56.157 644-644/com.example.MEM I/CMD﹕ 返回结果=nand.ko
03-23 16:42:56.167 644-644/com.example.MEM I/CMD﹕ 返回结果=proc
03-23 16:42:56.167 644-644/com.example.MEM I/CMD﹕ 返回结果=sbin
03-23 16:42:56.167 644-644/com.example.MEM I/CMD﹕ 返回结果=sun7i-ir.ko
03-23 16:42:56.167 644-644/com.example.MEM I/CMD﹕ 返回结果=system
03-23 16:42:56.167 644-644/com.example.MEM I/CMD﹕ 返回结果=ueventd.goldfish.rc
03-23 16:42:56.167 644-644/com.example.MEM I/CMD﹕ 返回结果=ueventd.sun7i.rc
03-23 16:42:56.167 644-644/com.example.MEM I/CMD﹕ 返回结果=null
String cmd="ll"打印结果:
03-23 16:46:52.337 3166-3166/com.example.MEM W/System.err﹕ java.io.IOException: Error running exec(). Command: [ll] Working Directory: null Environment: null
03-23 16:46:52.337 3166-3166/com.example.MEM W/System.err﹕ at java.lang.ProcessManager.exec(ProcessManager.java:211)
03-23 16:46:52.347 3166-3166/com.example.MEM W/System.err﹕ at java.lang.Runtime.exec(Runtime.java:168)
03-23 16:46:52.347 3166-3166/com.example.MEM W/System.err﹕ at java.lang.Runtime.exec(Runtime.java:241)
03-23 16:46:52.347 3166-3166/com.example.MEM W/System.err﹕ at java.lang.Runtime.exec(Runtime.java:184)
03-23 16:46:52.347 3166-3166/com.example.MEM W/System.err﹕ at com.example.MEM.MyActivity.ssss(MyActivity.java:464)
03-23 16:46:52.347 3166-3166/com.example.MEM W/System.err﹕ at com.example.MEM.MyActivity.access$000(MyActivity.java:32)
03-23 16:46:52.347 3166-3166/com.example.MEM W/System.err﹕ at com.example.MEM.MyActivity$1.onClick(MyActivity.java:90)
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。