From 43cc6f5519ffd534c09ece37ca5793e31ed4b187 Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Wed, 28 Sep 2016 15:02:17 +0200 Subject: [PATCH] Add printenv for linux (PY-15085) --- bin/linux/printenv.py | 18 ++++++++++++++++++ .../src/com/intellij/util/EnvironmentUtil.java | 8 +++++--- 2 files changed, 23 insertions(+), 3 deletions(-) create mode 100755 bin/linux/printenv.py diff --git a/bin/linux/printenv.py b/bin/linux/printenv.py new file mode 100755 index 000000000000..a60959ca82eb --- /dev/null +++ b/bin/linux/printenv.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python + +# Dumps environment variables into specified file. +# Format: zero-separated "name=value" pairs in platform encoding. + +import os +import sys + +if len(sys.argv) != 2: + raise Exception('Exactly one argument expected') + +f = open(sys.argv[1], 'wb') +try: + for key, value in os.environ.items(): + s = '%s=%s\0' % (key, value) + f.write(s.encode('utf-8')) +finally: + f.close() diff --git a/platform/util/src/com/intellij/util/EnvironmentUtil.java b/platform/util/src/com/intellij/util/EnvironmentUtil.java index 1d6428dadfd6..dc31d03bd7c4 100644 --- a/platform/util/src/com/intellij/util/EnvironmentUtil.java +++ b/platform/util/src/com/intellij/util/EnvironmentUtil.java @@ -161,10 +161,11 @@ public class EnvironmentUtil { public static class ShellEnvReader { public Map readShellEnv() throws Exception { + String os = SystemInfo.isLinux ? "linux" : "mac"; File reader = FileUtil.findFirstThatExist( PathManager.getBinPath() + "/printenv.py", - PathManager.getHomePath() + "/community/bin/mac/printenv.py", - PathManager.getHomePath() + "/bin/mac/printenv.py"); + PathManager.getHomePath() + "/community/bin/" + os + "/printenv.py", + PathManager.getHomePath() + "/bin/" + os + "/printenv.py"); if (reader == null) { throw new Exception("bin:" + PathManager.getBinPath()); } @@ -185,7 +186,8 @@ public class EnvironmentUtil { } @NotNull - protected static Map runProcessAndReadEnvs(@NotNull List command, @NotNull File envFile, String lineSeparator) throws Exception { + protected static Map runProcessAndReadEnvs(@NotNull List command, @NotNull File envFile, String lineSeparator) + throws Exception { ProcessBuilder builder = new ProcessBuilder(command).redirectErrorStream(true); builder.environment().put(DISABLE_OMZ_AUTO_UPDATE, "true"); Process process = builder.start(); -- 2.32.0