As a question that you associate with states, it is better to read and discard output and error streams. If you are using apache commons io, something like
new Thread(new Runnable() {public void run() {IOUtils.copy(process.getInputStream(), new NullOutputStream());}}).start(); new Thread(new Runnable() {public void run() {IOUtils.copy(process.getErrorStream(), new NullOutputStream());}}).start();
You want to read and discard stdout and stderr in a separate thread to avoid problems such as blocking a process when it writes enough information to stderr or stdout to fill the buffer.
If you are worried about having two threads, see question
I don't think you need to worry about catching IOExceptions when copying stdout, stdin to a NullOutputStream, because if there is a reading of an IOException from the stdout / stdin process, this is probably due to the process itself being dead and writes to NullOutputStream will never throw an exception.
You do not need to check the return status of waitFor ().
Do you want to wait for the process to complete? If so, you can do
while(true) { try { process.waitFor(); break; } catch(InterruptedException e) {
After looking at the link you provided, you need to close the threads when the process is complete, but destroy will do it for you.
So, in the end, the method becomes,
public void close(Process process) { if(process == null) return; new Thread(new Runnable() {public void run() {IOUtils.copy(process.getInputStream(), new NullOutputStream());}}).start(); new Thread(new Runnable() {public void run() {IOUtils.copy(process.getErrorStream(), new NullOutputStream());}}).start(); while(true) { try { process.waitFor();