所以,我想能夠編寫一個應用程序,可以打開並顯示logcat消息,dmesg,並且還能夠運行命令,如'ls''貓「回聲」'cd'。Android Runtime.getRuntime()。exec()導航通過目錄
如果我做到以下幾點:
nativeProc = Runtime.getRuntime().exec("ls\n");
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(nativeProc.getOutputStream()));
BufferedReader in = new BufferedReader(new InputStreamReader(nativeProc.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
full = full + "\n" + line;
}
我可以把文字「滿」到文本查看,看到的根目錄。
但是,這就是我所能做的一切。比方說,我想找到一個目錄,並改變它,我遇到了麻煩。
所以,如果我這樣做:
nativeProc = Runtime.getRuntime().exec("ls\n");
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(nativeProc.getOutputStream()));
BufferedReader in = new BufferedReader(new InputStreamReader(nativeProc.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
full = full + "\n" + line;
}
/* Code here to confirm the existing of a directory*/
nativeProc = Runtime.getRuntime().exec("cd tmp\n");
BufferedReader in2 = new BufferedReader(new InputStreamReader(nativeProc.getInputStream()));
line = null;
String test = "\nStart1:\n";
while ((line = in2.readLine()) != null) {
test = test + "\n" + line;
}
我什麼也沒得到兩個 「全面」 和 「文本」
任何想法?