Java Process run operating system command and wait until command is terminated.

Description

Java Process run operating system command and wait until command is terminated.


public class Main {
  public static void main(String args[]) {
    Runtime r = Runtime.getRuntime();
    Process p = null;//from   ww  w .j av  a  2s  .  c  o  m

    try {
      p = r.exec("notepad");
      p.waitFor();
    } catch (Exception e) {
      System.out.println("Error executing notepad.");
    }
    System.out.println("Notepad returned " + p.exitValue());
  }
}



PreviousNext

Related