public static ProcessOutput getProcessOutput(@NotNull GeneralCommandLine cmd, @Nullable String homePath,
                                               @Nullable @NonNls Map<String, String> extraEnv,
                                               int timeout,
                                               byte @Nullable [] stdin, boolean needEOFMarker,
                                               @Nullable @Nls(capitalization = Nls.Capitalization.Title) String customTitle) {
    if (homePath == null || !new File(homePath).exists()) {
      return new ProcessOutput();
    }
    final Map<String, String> systemEnv = EnvironmentUtil.getEnvironmentMap();
    final Map<String, String> expandedCmdEnv = mergeEnvVariables(systemEnv, cmd.getEnvironment());
    final Map<String, String> env = extraEnv != null ? mergeEnvVariables(expandedCmdEnv, extraEnv) : expandedCmdEnv;
    PythonEnvUtil.resetHomePathChanges(homePath, env);
    try {

      final GeneralCommandLine commandLine = cmd.withWorkDirectory(homePath).withEnvironment(env);

      final PythonSdkFlavor flavor = PythonSdkFlavor.getFlavor(commandLine.getExePath());

      final CommandLinePatcher cmdLinePatcher = flavor != null ? flavor.commandLinePatcher() : null;
      if (cmdLinePatcher != null) {
        cmdLinePatcher.patchCommandLine(cmd);
      }

      final CapturingProcessHandler processHandler = new CapturingProcessHandler(commandLine);
      if (stdin != null) {
        final OutputStream processInput = processHandler.getProcessInput();
        assert processInput != null;
        processInput.write(stdin);
        if (SystemInfo.isWindows && needEOFMarker) {
          processInput.write(SUBSTITUTE);
          processInput.flush();
        }
        else {
          processInput.close();
        }
      }
      if (SwingUtilities.isEventDispatchThread()) {
        final ProgressManager progressManager = ProgressManager.getInstance();
        final Application application = ApplicationManager.getApplication();
        assert application.isUnitTestMode() ||
               application.isHeadlessEnvironment() ||
               !application.isWriteAccessAllowed() : "Background task can't be run under write action";
        String dialogTitle = customTitle != null ? customTitle : PySdkBundle.message("python.sdk.run.wait");
        return progressManager.runProcessWithProgressSynchronously(() -> processHandler.runProcess(timeout), dialogTitle , false, null);
      }
      else {
        return processHandler.runProcess();
      }
    }
    catch (ExecutionException | IOException e) {
      return getOutputForException(e);
    }
  }
public static ProcessOutput getProcessOutput(@NotNull GeneralCommandLine cmd, @Nullable String homePath,
                                               @Nullable @NonNls Map<String, String> extraEnv,
                                               int timeout,
                                               byte @Nullable [] stdin, boolean needEOFMarker,
                                               @Nullable @Nls(capitalization = Nls.Capitalization.Title) String customTitle)