When using ProcessBuilder, how do I set an environment variable in the subprocess?

John Zukowski

Get the set of environment variables by getting a Map with the environment() method. Then, add variables with the put(key, value) method of Map.

   ProcessBuilder processBuilder = new ProcessBuilder(
                                       command, arg1, arg2);
   Map<String, String> env = processBuilder.environment();
   env.put("var1", "value");
0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact