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...