Start a new process

Process start()
Starts a new process using the attributes of this process builder.

import java.io.File;
import java.util.Map;

public class Main{
  public static void main(String args[]) {

    try {
      ProcessBuilder pb = new ProcessBuilder("myCommand", "myArg1", "myArg2");
      Map<String, String> env = pb.environment();
      env.put("VAR1", "myValue");
      env.remove("anotherValue");
      pb.directory(new File("myDir"));
      Process p = pb.start();
    } catch (Exception e) {
      System.out.println("Error executing notepad.");
    }
  }
}
  
Home 
  Java Book 
    Essential Classes  

ProcessBuilder:
  1. ProcessBuilder class
  2. Create ProcessBuilder
  3. Get/set the working directory
  4. Get the environment variables
  5. Start a new process