AndroidでgetRuntime().exec()を使用してコンソール アプリケーションと通信します。
このコード:
Process process = Runtime.getRuntime().exec(true ? "su" : "sh");
// InputStream for program
DataOutputStream os = new DataOutputStream(process.getOutputStream());
//I output info on screen in Gobbler
StreamGobbler errorGobbler = new
StreamGobbler(process.getErrorStream(), "ERROR");
StreamGobbler outputGobbler = new
StreamGobbler(process.getInputStream(), "OUTPUT");
command1が実行されたことをどのように知ることができますか?
os.writeBytes(command1 + "\n");
// Here
os.writeBytes(command2 + "\n");
process.waitFor()この Process オブジェクトが表すプロセスが終了するまで待機します。
ありがとう!
コマンド 1 の出力を取得した後、コマンド 2 を知ることができます。
これは重複した質問ではありません。@Bill the Lizard、私の場合、process.watFor()は実行されません。そして、 os.write("exit"+"\n")を送信しないで待機します。私の質問には通常の答えがないと思います。唯一の方法 - プロセスの出力を解析します。