I want that my Java Programm 3 external Programms runs. But they should be run NOT in parallel. Programm 1 should output a File, this File is the Input for Programm 2, The output for Programm 2 should be the Input for Programm 3. And the Java Programm should NOT terminate, when the external programms terminate: This is my code but it does not work. Can anyone pls help me!
boolean var = true;
ProcessBuilder processBuilder = new ProcessBuilder("cmd", "/c",
"start", "C:\\Users\\Rosina\\Desktop\\Riss\\winlibs\\riss3g64", "C:\\Users\\Rosina\\Desktop\\out.cnf", "C:\\Users\\Rosina\\Desktop\\pruv.txt" );
Process process = processBuilder.start();
while(program.exists() && var) {
ProcessBuilder processBuilder3 = new ProcessBuilder("cmd", "/c",
"start", "C:\\Users\\Rosina\\Desktop\\Riss\\winlibs\\riss3g64", "C:\\Users\\Rosina\\Desktop\\out1.cnf", "C:\\Users\\Rosina\\Desktop\\hahaaaaaaaaaaaaaaafffa2.txt" );
Process process2 = processBuilder3.start();
var = false;
}
If Programm 1 has not produce the output, the file program does not exist, and Programm 2 can not start execution...where is my mistake...the code does not work...
-
1Process.waitFor() will help you achieve sequential execution of the programs.hmjd– hmjd2014年10月17日 14:45:16 +00:00Commented Oct 17, 2014 at 14:45
1 Answer 1
You need to wait on the process you launched to finish. You can block the current thread of execution until the process finishes with
process.waitFor()