如何从Android App运行linux命令并读取输出。例如:检索“ls -lh”的输出并在TextView中打印为文本?
答案 0 :(得分:3)
试试这个:
try{
Process process;
process = Runtime.getRuntime().exec("ls -lh");
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
将此in
发布到TextView后。