I am trying to run command line commands from Java and a quick sanity check made me realize that the reason I am having trouble is that I can\'t get the pr.waitFor()
Process.waitFor() blocks the current thread until the process has terminated, at which point the execution control returns to the thread that spawned the process.
In the posted code, once the process has terminated (i.e., after the Process.waitFor invocation), the input stream of the now terminated process no longer has any data that can be read. Reading the contents of the stream and printing it out, will therefore not result in any tangible input.
If you need to read the contents of the stream, you'll need to spawn a new thread that will take care of the necessary activities of reading the input stream and writing to the output stream as required, before the child process terminates.
Or you could perform the reading and writing in the same thread, but before you wait for the child process to terminate. In other words, you'll need to switch the sequence of the lines containing pr.waitFor(); and the lines that read from the InputStream.
Related question on SO: