diff --git a/platform/util/src/com/intellij/util/EnvironmentUtil.java b/platform/util/src/com/intellij/util/EnvironmentUtil.java index 27e4077b6d52..66c9a1012ecf 100644 --- a/platform/util/src/com/intellij/util/EnvironmentUtil.java +++ b/platform/util/src/com/intellij/util/EnvironmentUtil.java @@ -187,25 +187,44 @@ public class EnvironmentUtil { LOG.info("loading shell env: " + StringUtil.join(command, " ")); - return runProcessAndReadEnvs(command, envFile, "\0"); + return dumpProcessEnvToFile(command, envFile, "\0"); } finally { FileUtil.delete(envFile); } } + @NotNull + protected Map dumpProcessEnvToFile(@NotNull List command, @NotNull File envFile, String lineSeparator) + throws Exception { + return runProcessAndReadEnvs(command, envFile, lineSeparator); + } + @NotNull protected static Map runProcessAndReadEnvs(@NotNull List command, @NotNull File envFile, String lineSeparator) throws Exception { return runProcessAndReadEnvs(command, null, envFile, lineSeparator); } - - @NotNull + + @NotNull protected static Map runProcessAndReadEnvs(@NotNull List command, - @Nullable File workingDir, - @NotNull File envFile, + @Nullable File workingDir, + @NotNull File envFile, + String lineSeparator) throws Exception { + return runProcessAndReadEnvs(command, workingDir, null, envFile, lineSeparator); + } + + @NotNull + protected static Map runProcessAndReadEnvs(@NotNull List command, + @Nullable File workingDir, + @Nullable Map envs, + @NotNull File envFile, String lineSeparator) throws Exception { ProcessBuilder builder = new ProcessBuilder(command).redirectErrorStream(true); + if (envs != null) { + // we might need default environment for the process to launch correctly + builder.environment().putAll(envs); + } if (workingDir != null) builder.directory(workingDir); builder.environment().put(DISABLE_OMZ_AUTO_UPDATE, "true"); Process process = builder.start(); diff --git a/python/src/com/jetbrains/python/run/PyVirtualEnvReader.kt b/python/src/com/jetbrains/python/run/PyVirtualEnvReader.kt index e0e6c1dd5f55..29402cbca2b0 100644 --- a/python/src/com/jetbrains/python/run/PyVirtualEnvReader.kt +++ b/python/src/com/jetbrains/python/run/PyVirtualEnvReader.kt @@ -67,6 +67,11 @@ class PyVirtualEnvReader(val virtualEnvSdkPath: String) : EnvironmentUtil.ShellE } } + override fun dumpProcessEnvToFile(command: MutableList, envFile: File, lineSeparator: String?): MutableMap { + // pass shell environment for correct virtualenv environment setup (virtualenv expects to be executed from the terminal) + return runProcessAndReadEnvs(command, null, EnvironmentUtil.getEnvironmentMap(), envFile, lineSeparator) + } + private fun readVirtualEnvOnWindows(activate: Pair): MutableMap { val activateFile = FileUtil.createTempFile("pycharm-virualenv-activate.", ".bat", false) val envFile = FileUtil.createTempFile("pycharm-virualenv-envs.", ".tmp", false)