waitFor() not a bug?

The way the Process.waitFor() works now is that if there is output from the program to the buffers, waitFor() will hang and wait for the program that ran the code to empty the buffer, but there is also no easy way to check if the process ended (except for checking for the exitValue and seeing if it throws an error, which doesn't seem to work either) so how long can we be expected to empty the buffer for?

What if the program we ran outputs things to System.out once every 2-10 minutes for an hour? It's easy enough to pull things out of the buffer but when that ends the program will continue until it reaches the waitFor() and in the meantime 10 minutes passed and the buffer is full again, and the waitFor() hangs.

If there was an easy way to check if the process is still running we could empty the buffer for the duration of that time, but we can't do this either. (The whole exitValue work around doesn't seem to work for me, and in any case, it's not a solution to be checking every second if some method throws an exception.)

It seems like this has been a well known bug for sometime. Am I misunderstanding the situation?

Thanks,

[1177 byte] By [mikebasa] at [2007-11-27 10:51:48]
# 1

Have you read:

http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

dwga at 2007-7-29 11:33:35 > top of Java-index,Java Essentials,Java Programming...
# 2

Yes I did.

He just creates a new thread to empty the buffer, so it also runs until the buffer is empty and ends, then what happens when the buffer fills up again?

mikebasa at 2007-7-29 11:33:35 > top of Java-index,Java Essentials,Java Programming...
# 3

Erm, I think I misunderstood what he did. Nevermind, my apologies. Still there should be a way to check if a process you started is still running.

what are the policies with regards to using javaworld code (I want to use the class from that article) for non-profit/academic use?

mikebasa at 2007-7-29 11:33:35 > top of Java-index,Java Essentials,Java Programming...
# 4

Not quite sure, you can most likely use them freely as there is no copyright specified.

dwga at 2007-7-29 11:33:35 > top of Java-index,Java Essentials,Java Programming...