バイナリは正常に実行されますが、Java を介してバイナリ ('C' で記述) を実行しようとしています。「Enter」キーストロークが押されるまで、実行制御はこのコードに返されません (ブロックされます)。この問題のため、'prcs.waitfor() == 0' は実行されず、ユーザーはバイナリ実行が成功したかどうかわかりません。「Enter」キーストローク (//r) を送信するために OutputStream に BufferedWriter を作成しようとしましたが、機能しません。実行制御がこのコードに戻り、「prcs.waitfor() ==0」が実行されるように、ここで行う必要があること。最初のコマンドの実行の成功に依存する別のコマンドを実行する必要があります。私はこれで立ち往生しています:(
// Start ProcessBuilder, 'str' contains a command
ProcessBuilder pbuilder = new ProcessBuilder(str);
pbuilder.directory(new File("/root/workspace/Project1"));
pbuilder.redirectErrorStream(true);
Process prcs = pbuilder.start();
AForm.execStatustext.append("\n=> Process is:" + prcs);
// Read output
StringBuilder out = new StringBuilder();
BufferedReader bfrd = new BufferedReader(new InputStreamReader(process.getInputStream()));
String current_line = null, previous_line = null;
while ((current_line = bfrd.readLine()) != null) {
if (!line.equals(previous_line)) {
previous_line = current_line;
out.append(current_line).append('\n');
//System.out.println(line);
}
}
//process.getInputStream().close();
// Send 'Enter' keystroke through BufferedWriter to get control back
BufferedWriter bfrout = new BufferedWriter(new OutputStreamWriter(prcs.getOutputStream()));
bfrout.write("\\r");
bfrout.newLine();
bfrout.flush();
bfrout.write("\\r");
bfrout.newLine();
bfrout.flush();
//process.getOutputStream().close();*/
if (prcs.waitFor() == 0)
System.out.println("Commands executed successfully");
System.exit(0);