public @NotNull Pair<String, Map<String, String>> readBatOutputAndEnv(@Nullable Path batchFile,
                                                                        @Nullable List<@NotNull String> args,
                                                                        @NotNull String cmdExePath,
                                                                        @NotNull Consumer<? super @NotNull Map<String, String>> scriptEnvironmentProcessor) throws IOException {
    if (batchFile != null && !Files.exists(batchFile)) {
      throw new NoSuchFileException(batchFile.toString());
    }
    final Path envDataFile = Files.createTempFile("intellij-cmd-env-data.", ".tmp"); // NON-NLS

    final List<String> callArgs = new ArrayList<>();
    if (batchFile != null) {
      callArgs.add("call");
      callArgs.add(batchFile.toString());
      if (args != null) {
        callArgs.addAll(args);
      }
      // Scripts like `vcvarsall.bat` may write debugging logs to stdout.
      // They would interfere with environment variables, if there was no stream redirection.
      callArgs.add("1>&2");
      callArgs.add("&&");
    }

    callArgs.add((System.getProperty("java.home") + "/bin/java").replace('/', File.separatorChar)); // NON-NLS
    callArgs.add("-cp"); // NON-NLS
    callArgs.add(PathManager.getJarPathForClass(ReadEnv.class));
    callArgs.add(ReadEnv.class.getCanonicalName());

    callArgs.add(">");
    callArgs.add(envDataFile.toString());
    callArgs.add("||");
    callArgs.add("exit"); // NON-NLS
    callArgs.add("/B"); // NON-NLS
    callArgs.add("%ERRORLEVEL%"); // NON-NLS

    final List<@NonNls String> cl = new ArrayList<>();
    cl.add(cmdExePath);
    cl.add("/c");
    cl.add(prepareCallArgs(callArgs));
    Map.Entry<String, Map<String, String>> entry =
      runProcessAndReadOutputAndEnvs(cl, batchFile != null ? batchFile.getParent() : null, scriptEnvironmentProcessor, envDataFile);
    return new Pair<>(entry.getKey(), entry.getValue());
  }
public @NotNull Pair<String, Map<String, String>> readBatOutputAndEnv(@Nullable Path batchFile,
                                                                        @Nullable List<@NotNull String> args,
                                                                        @NotNull String cmdExePath,
                                                                        @NotNull Consumer<? super @NotNull Map<String, String>> scriptEnvironmentProcessor)