// using ProcessBuilder to spawn a Java class in another JVM. ProcessBuilder pb = new ProcessBuilder( "java.exe", "-jar", "otherprog.jar", "42" /* a parameter to OtherProg */); Map<String, String> env = pb.environment(); // insert set FRUIT=strawberry into environment just for our children env.put( "FRUIT", "strawberry" ); // remove set LIVERCOURSE=YES from environment just for our children env.remove( "LIVERCOURSE" ); // modify set WINE=pinot to WINE=pinot blanc env.put( "WINE", env.get("WINE") + " blanc" ); // set up the working directory; note it is not called setDirectory pb.directory( "/progdir" ); // merge child's error and normal output streams. // Note it is not called setRedirectErrorStream. pb.redirectErrorStream( true ); Process p = pb.start(); // From here on it, it behaves just like exec, since you have the // exact same Process object. // ...