私のアプリは、別のスレッドでプロセスを使用していくつかのコマンドを実行し、それらから入力を取得します。
process = Runtime.getRuntime().exec("su");
out = new DataOutputStream(process.getOutputStream());
アプリは次のようにコマンドをプロセスに送信します。
public void setCommands(String[] commands)
{
try{
for(String command : commands){
out.writeBytes(command + "\n");
}
out.writeBytes("exit\n"); //if I comment this line the commands get lost
out.flush();
}catch(IOException e){
e.printStackTrace();
}
}
次に、スレッドは BufferedReaders を使用してプロセスから入力を読み取り、それをメイン スレッドに送信すると、初めて正常に動作します。問題は、同じプロセスを複数の呼び出しで再利用したいということですsetCommands()
が、最初の呼び出しの後、プロセスの OutputStream がout.writeBytes("exit\n");
ステートメントで閉じられます。この行にコメントすると、out.flush()
開始の効果がないように見えます。誰かが私になぜこれが起こっているのか、どうすればこれを正しく行うことができるのか説明してもらえますか?