Commits

James Dumay committed bf17c06

BAM-8290 ProcessUtils doesn't use ProcessBuilder for non-windows. There was no good reason here NOT to use ProcessBuilder.

Comments (0)

Files changed (1)

src/main/java/com/atlassian/utils/process/ExternalProcess.java

       * as the user typically won't use characters that aren't defined for his locale. But then again, they might..
      */
     private Process createWinProcess(String[] cmdArray, String[] environment, File workingDir) throws IOException {
-        Map<String, String> newEnv = new HashMap<String, String>();
-        if (environment == null) {
-            // inherit the environment of the current process
-            newEnv.putAll(System.getenv());
-        } else {
-            // add the env entries
-            for (String env: environment) {
-                String[] values = env.split("=");
-                if (values.length > 1) {
-                    newEnv.put(values[0], values[1]);
-                }
-            }
-        }
+        Map<String, String> newEnv = splitEnvironment(environment);
         int extraArgs = 4;
         String[] i18n = new String[cmdArray.length + extraArgs];
         i18n[0] = "cmd";
         env.putAll(newEnv);
         return pb.start();
     }
-    
+
+    private Map<String, String> splitEnvironment(final String[] environment)
+    {
+        Map<String, String> newEnv = new HashMap<String, String>();
+        if (environment == null) {
+            // inherit the environment of the current process
+            newEnv.putAll(System.getenv());
+        } else {
+            // add the env entries
+            for (String env: environment) {
+                String[] values = env.split("=");
+                if (values.length > 1) {
+                    newEnv.put(values[0], values[1]);
+                }
+            }
+        }
+        return newEnv;
+    }
+
     private Process createProcess(String[] cmdArray, String[] environment, File workingDir) throws IOException {
     	if (isWindows()) {
     		return createWinProcess(cmdArray, environment, workingDir);
     	} else {
-    		return Runtime.getRuntime().exec(cmdArray, environment, workingDir);
+            //But what about BeOS?!
+            final ProcessBuilder processBuilder = new ProcessBuilder()
+                    .command(cmdArray)
+                    .directory(workingDir);
+
+            processBuilder.environment().putAll(splitEnvironment(environment));
+
+    		return processBuilder.start();
     	}
     }