上QQ阅读APP看书,第一时间看更新
Taking control of external processes
Up to JDK 9, if you wanted to create a Java process and handle process input/output, you had to use one of the following approaches:
- The Runtime.getRuntime.exec() method, which allows us to execute a command in a separate OS process. Using this approach would require you to get a java.lang.Process instance over which to provide certain operations in order to manage the external process.
- The new java.lang.ProcessBuilder class, which has some more enhancements with regard to interacting with the external process. You would also need to create a java.lang.Process instance to represent the external process.
Both approaches were inflexible and also nonportable, as the set of commands executed by the external processes were highly dependent on the operating system. An additional effort had to be exerted in order to make the particular process operations portable across multiple operating systems. Chapter 9, Making Use of the Process API, is dedicated to the new process API, providing developers with the knowledge to create and manage external processes in a much easier way.