私はアンドロイドでコマンドを発行して結果を通知するアプリケーションを作ろうとしています。これは、より多くの出力を待つコマンドが正しく処理されないという例外を除いてうまくいっているようです。私はコマンド "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