1

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...

hmjd
122k21 gold badges216 silver badges259 bronze badges
asked Oct 17, 2014 at 14:41
1
  • 1
    Process.waitFor() will help you achieve sequential execution of the programs. Commented Oct 17, 2014 at 14:45

1 Answer 1

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()
answered Oct 17, 2014 at 14:45
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.