我想让一个应用程序,将允许我在Android中发出命令,并给我结果。这似乎工作正常,但有一些例外,即等待一段时间以获得更多输出的命令未得到正确处理。我试图发出命令“su & & nmap -sS 192.168.1.1”,我得到的所有输出是nmap已经启动。有谁知道一种方法,不仅可以获得nmap已经启动的输出,还可以使用下面代码的修改版本进行扫描的结果。Android java InputStreamReader
try {
EditText inputTxt = (EditText) findViewById(R.id.input);
String str = inputTxt.getText().toString();
Process command = Runtime.getRuntime().exec(str);
BufferedReader reader = new BufferedReader(
new InputStreamReader(command.getInputStream()));
int read;
char[] buffer = new char[4096];
StringBuffer output = new StringBuffer();
while ((read = reader.read(buffer)) > 0) {
output.append(buffer, 0, read);
}
reader.close();
TextView textView = (TextView) findViewById(R.id.textView);
textView.setText(output);
}
catch (IOException e) {
Log.e("Run_Command", Log.getStackTraceString(e));
}
可能'su'只是在等待密码吗? –
您需要关闭输入到输入流的输出流。 – EJP