For some terminal commands, they repeatedly output. For example, for something that’s generating a file, it may output the percent that it is complete.
I know how to call terminal commands in Java using
Process p = Runtime.getRuntim().exec("command goes here");
but that doesn’t give me a live feed of the current output of the command. How can I do this so that I can do a System.out.println() every 100 milliseconds, for example, to see what the most recent output of the process was.
You need to read
InputStreamfrom the process, here is an example:Edit I modified the code as suggested here to receive the
errStreamwith thestdInputFor debugging purpose, you can read the input as bytes instead of using
readLinejust in case that the process does not terminate messages withnewLine