You can use the newer ProcessBuilder
class, which has more options than the Runtime.exec
method. The reason why you don't see any output is because the standard output stream of the new process is by default connected to the JVM via a pipe. You can make the new process inherit the JVM's standard output using the redirectOutput
method:
ProcessBuilder pb = new ProcessBuilder("ls");
pb.redirectOutput(Redirect.INHERIT);
Process p = pb.start();
You can get a similar result using a shell redirection to the controlling terminal:
ProcessBuilder pb = new ProcessBuilder("sh", "-c", "ls > /dev/tty");
Process p = pb.start();