private ProcessOutput runProcess()

in powershell-agent/src/main/java/jetbrains/buildServer/powershell/agent/detect/cmd/DetectionRunner.java [53:78]


  private ProcessOutput runProcess(@NotNull final GeneralCommandLine cl) throws ExecutionException {
    final int attempts = TeamCityProperties.getInteger("teamcity.powershell.detector.attempts", 1);
    final int timeout = TeamCityProperties.getInteger("teamcity.powershell.detector.timeout.msec", 20000);
    for (int attempt = 1; attempt <= attempts; attempt++) {
      final CapturingProcessHandler handler = new CapturingProcessHandler(cl.createProcess(), StandardCharsets.UTF_8);
      final ProcessOutput result = handler.runProcess(timeout);
      final String errorOutput = result.getStderr();
      if (!isEmptyOrSpaces(errorOutput)) {
        logProcessOutput(result);
        throw new ExecutionException(errorOutput);
      }
      if (result.isTimeout()) {
        logProcessOutput(result);
        int leftAttempts = attempts - attempt;
        if (leftAttempts > 0) {
          LOG.warn(String.format("PowerShell detection timed out, %d %s left",
                  leftAttempts, StringUtil.pluralize("attempt", leftAttempts)
          ));
          continue;
        }
        throw new ExecutionException("Process execution of [" + cl.getCommandLineString() + "] has timed out. Timeout is set to " + timeout + " msec.");
      }
      return result;
    }
    throw new ExecutionException("Failed to detect PowerShell"); // must be unreachable
  }