Launching a Process
As mentioned earlier, a process is launched with exec()
. Let's look at a simple example where we will call the Java compiler, something that is done the same way from the terminal on any operating system:
import java.io.IOException; public class Example02 { public static void main(String[] args) { Runtime runtime = Runtime.getRuntime(); try { Process process = runtime.exec("firefox"); } catch (IOException ioe) { System.out.println("WARNING: something happened with exec"); } } }
When running this example, if you happen to have Firefox installed, it will launch automatically. You could change that to be any other application on your computer. The program will exit with no error, but it will not do anything besides that.
Now, let...