Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This compliant solution redirects the process's error stream to its input stream. Thus, the program can drain the single output stream without fear of blockage.

Code Block
bgColor#ffcccc#ccccff
public class Exec {
  public static void main(String args[]) throws IOException, InterruptedException {
    ProcessBuilder pb = new ProcessBuilder("notemaker");
    pb = pb.redirectErrorStream(true);
    Process proc = pb.start();
    InputStream is = proc.getInputStream();
    int c;
    while ((c = is.read()) != -1)
      System.out.print((char) c);
    int exitVal = proc.waitFor();   
  }
}

...