- Create an instance of ProcessBuilder:
ProcessBuilder pb = new ProcessBuilder();
- Set the command to printenv and the output and error streams to the same as that of the current Java process:
- Provide the environment variables, COOKBOOK_VAR1 with the value, First variable, COOKBOOK_VAR2 with the value, Second variable, and COOKBOOK_VAR3 with the value, Third variable:
Map<String, String> environment = pb.environment(); environment.put("COOKBOOK_VAR1", "First variable"); environment.put("COOKBOOK_VAR2", "Second variable"); environment.put("COOKBOOK_VAR3", "Third variable");
- Start the process and wait for it to complete:
Process p = pb.start(); int exitValue = p.waitFor();
The complete ...