Execuate a system command

Process exec(String command)
Executes the specified string command in a separate process.
Process exec(String[] cmdarray)
Executes the specified command and arguments in a separate process.
Process exec(String[] cmdarray, String[] envp)
Executes the specified command and arguments in a separate process with the specified environment.
Process exec(String[] cmdarray, String[] envp, File dir)
Executes the specified command and arguments in a separate process with the specified environment and working directory.
Process exec(String command, String[] envp)
Executes the specified string command in a separate process with the specified environment.
Process exec(String command, String[] envp, File dir)
Executes the specified string command in a separate process with the specified environment and working directory.

import java.io.IOException;

public class Main {
  public static void main(String[] args) {
    Runtime runtime = Runtime.getRuntime();

    try {
      Process pro = runtime.exec("notepad.exe");
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}

Wait until notepad is terminated.

 
public class Main {
  public static void main(String args[]) {
    Runtime r = Runtime.getRuntime();
    Process p = null;
    try {
      p = r.exec("notepad");
      p.waitFor();
    } catch (Exception e) {
      System.out.println("Error executing notepad.");
    }
    System.out.println("Notepad returned " + p.exitValue());
  }
}
Home 
  Java Book 
    Essential Classes  

Runtime:
  1. Runtime class
  2. Get the instance of a runtime
  3. Get the memory in your Java virtual machine
  4. Shut down hook
  5. Get the available processor
  6. Exit and halt Java virtual machine
  7. Run garbage collector and finalization methods
  8. Execuate a system command