This 'unfolded' static method makes it convenient to print a Process' streams
without causing IO to lock up. There are also methods to collect the output into StringBuilder in the same class. For theory, see the article here. The whole source is HERE

 

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;


/**
 * Various IO convenience routines
 *
 * @author Charles Johnson
 * @version 1.0
 */
public class IOUtils {
    // Various options for closing streams

    public static final int CLOSE_NEITHER  = 1;
    public static final int CLOSE_INPUT = 2;
    public static final int CLOSE_OUTPUT = 4;

    /**
     * Copy stderr and stdout of a Process to the console
     *
     * @param p The Process' streams we want to print
     */
    public static void outputProcessStreams(final Process p) {
        Thread runStdout = new Thread() {
            public void run() {
                IOUtils.copyStream(p.getInputStream(), System.out);
            }
        };

        runStdout.start();

        Thread runStderr = new Thread() {
            public void run() {
                IOUtils.copyStream(p.getErrorStream(), System.err);
            }
        };

        runStderr.start();
    }
+-- 74 lines: *

}