Process.waitFor() has the following syntax.
public abstract int waitFor() throws InterruptedException
In the following code shows how to use Process.waitFor() method.
// w ww .j a v a 2 s.co m public class Main { public static void main(String[] args) { try { // create a new process Process p = Runtime.getRuntime().exec("notepad.exe"); // cause this process to stop until process p is terminated p.waitFor(); // when you manually close notepad.exe this program will continue System.out.println("Waiting over."); } catch (Exception ex) { ex.printStackTrace(); } } }