private Process startProcess()

in src/com/pty4j/windows/cygwin/CygwinPtyProcess.java [69:122]


  private Process startProcess(String inPipeName,
                               String outPipeName,
                               String errPipeName,
                               String workingDirectory,
                               String[] command,
                               Map<String, String> environment,
                               File logFile,
                               boolean console) throws IOException {
    File nativeFile;
    try {
      nativeFile = PtyUtil.resolveNativeFile("cyglaunch.exe");
    } catch (Exception e) {
      throw new IOException(e);
    }
    String logPath = logFile == null ? "null" : logFile.getAbsolutePath();
    ProcessBuilder processBuilder =
      new ProcessBuilder(nativeFile.getAbsolutePath(), logPath, console ? "1" : "0", inPipeName, outPipeName, errPipeName);
    for (String s : command) {
      processBuilder.command().add(s);
    }
    if (workingDirectory != null) {
      processBuilder.directory(new File(workingDirectory));
    }
    processBuilder.environment().clear();
    processBuilder.environment().putAll(environment);
    final Process process = processBuilder.start();

    try {
      waitForPipe(myInputHandle);
      waitForPipe(myOutputHandle);
      if (myErrorHandle != null) waitForPipe(myErrorHandle);
    } catch (IOException e) {
      process.destroy();
      closeHandles();
      throw e;
    }

    new Thread() {
      @Override
      public void run() {
        while (true) {
          try {
            process.waitFor();
            break;
          }
          catch (InterruptedException ignore) { }
        }

        closePipes();
      }
    }.start();

    return process;
  }