- Create a list of ProcessBuilder objects, which will hold the ProcessBuilder instances participating in our pipeline. Also, redirect the output of the last process in the pipeline to the standard output of the current Java process:
List<ProcessBuilder> pipeline = List.of( new ProcessBuilder("cat", "iris.data.txt"), new ProcessBuilder("cut", "-d", ",", "-f", "5"), new ProcessBuilder("uniq", "-c") .redirectOutput(ProcessBuilder.Redirect.INHERIT) );
- Use the startPipeline() method of ProcessBuilder and pass the list of ProcessBuilder objects to start the pipeline. It will return a list of Process objects, each representing a ProcessBuilder object in the list:
List<Process> processes = ProcessBuilder.startPipeline(pipeline); ...