- Create an instance of ProcessBuilder by providing the required command and its options:
ProcessBuilder pBuilder = new ProcessBuilder("free", "-m");
An alternate way to specify the command and options is as follows:
- Set up the input and output streams for the process builder and other properties, such as the directory of execution and environment variables. After that, invoke start() on the ProcessBuilder instance to spawn the process and get a reference to the Process object:
Process p = pBuilder.inheritIO().start();
The inheritIO() function sets the standard I/O of the spawned subprocess to be the same as that of the current Java process.
- We then wait for the completion of the process, ...