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)
android 裡面沒有ll這個命令,用ls -l