【发布时间】:2012-06-22 21:15:29
【问题描述】:
我似乎无法让 runtime.exec 在我的 android 应用程序中工作。我已经尝试了许多 shell 实用程序,这是我正在使用的代码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
filesPrinter = (Button) findViewById(R.id.print_files);
filesPrinter.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
try {
Process proc = Runtime.getRuntime().exec("ls");
out = new BufferedWriter(new OutputStreamWriter(proc.getOutputStream()));
in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line;
while((line = in.readLine()) != null) {
System.out.println(line);
}
System.out.println("Done reading");
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
我没有收到错误,但也没有在 logcat 中得到任何东西。
【问题讨论】:
-
错误是什么?问题在哪里?您在发布之前阅读了 SO FAQ 吗?
-
@Astor 这个问题似乎是一个非常有效的问题,即使有关错误的更多详细信息确实会有所帮助。
-
我已经进行了编辑,没有错误,但我没有得到任何输出到 logcat
-
您是否尝试执行其他命令?例如尝试执行
ls -l。你调试过那个代码吗?
标签: java android runtime.exec