O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

There are two ways to let ProcessBuilder know which command to run:

  1. By passing the command and its options to the constructor while creating the ProcessBuilder object.
  2. By passing the command and its options as parameters to the command() method of the ProcessBuilder object.

Before spawning the process, we can do the following:

  • We can change the directory of execution by using the directory() method 
  • We can redirect the input stream, output stream, and error streams to file or to another process
  • We can provide the required environment variables for the subprocess

We will see all these activities in their respective recipes in this chapter.

A new process is spawned when the start() method is invoked and the caller gets a ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required