code: private static Thread createRunner(
          final String cmd, final JTextArea dest,
          final JDialog dialog, final JButton okButton) {
          return new Thread() {
              @Override
              public void run() {
                  Process p;
                  StringBuffer exit;
                  Thread log1;
                  Thread log2;
  
                  exit = new StringBuffer();
                  try {
                      try {
                          p = Runtime.getRuntime().exec(cmd);
                      } catch (IOException e) {
                          dest.append("\nexecution failed: " + e.getMessage());
                          return;
                      }
                      log1 = createLogger(p.getInputStream(), dest);
                      log2 = createLogger(p.getErrorStream(), dest);
                      log1.start();
                      log2.start();
                      System.out.println("waiting");
                      try {
                          log1.join();
                          log2.join();
                          // join the logger threads before waiting for
                          // the process - otherwise the exit code can be
                          // printed before the command output
                          exit.append("" + p.waitFor());
                      } catch (InterruptedException e) {
                          exit.append("interrupted");
                      }
                  } finally {
                      dest.append("\nfinished, exit= " + exit.toString());
                      okButton.setEnabled(true);
                      System.out.println("launcher done");
                  }
              }
          };
      }
docs: Create a new thread to execute the specified command.
  Enables the specified button when done.