Add printenv for linux (PY-15085)
authorDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Wed, 28 Sep 2016 13:02:17 +0000 (15:02 +0200)
committerDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Wed, 28 Sep 2016 13:02:17 +0000 (15:02 +0200)
bin/linux/printenv.py [new file with mode: 0755]
platform/util/src/com/intellij/util/EnvironmentUtil.java

diff --git a/bin/linux/printenv.py b/bin/linux/printenv.py
new file mode 100755 (executable)
index 0000000..a60959c
--- /dev/null
@@ -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()
index 1d6428dadfd6a49fbfa808f6606063fc5d48a18f..dc31d03bd7c49e659355f21debe8c33e4b314c5c 100644 (file)
@@ -161,10 +161,11 @@ public class EnvironmentUtil {
   public static class ShellEnvReader {
 
     public Map<String, String> 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<String, String> runProcessAndReadEnvs(@NotNull List<String> command, @NotNull File envFile, String lineSeparator) throws Exception {
+    protected static Map<String, String> runProcessAndReadEnvs(@NotNull List<String> 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();