In other languages (like bash and Python), when we spawn a child process, this new process will inherit the stdout and stderr from the parent. This means that any output from the child process will be printed to the terminal as well as the output from the parent.
How can we achieve the same behavior in Java?
My first try was:
proc = Runtime.getRuntime().exec(cmd);
But it won't work. Based on this answer and this answer, I've replaced the code with:
ProcessBuilder pb = new ProcessBuilder(cmd);
pb.redirectOutput(System.out);
pb.redirectError(System.err);
But this doesn't even compile, as the arguments are incompatible with the expected method parameters.