所以,我希望能够编写一个应用程序,可以打开和显示的logcat信息,dmesg的,也可以运行像'ls'的'猫''回声'CD命令。
So I want to be able to write an app that can turn on and display logcat messages, dmesg, and also be able to run commands like 'ls' 'cat' 'echo' 'cd.'
如果我做到以下几点:
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;
}
我可以把文字满到文本查看,看到的根目录。
I can put the text "full" to a Text View and see the root directory.
但是,这就是所有我能做的。比方说,我想找到一个目录,并改变它,我有麻烦了。
However, that's about all I can do. Let's say I want to find a directory, and change to it, I'm having trouble.
所以,如果我这样做:
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;
}
我什么也得不到为全和文本
I get nothing for both "full" and "text"
任何想法?
您可以与哪些文件夹应列出提供的路径执行ls
You can execute ls with provided path for which folders should be listed
Runtime.getRuntime().exec(new String[] { "ls", "\\tmp"});