Get the environment variables
Map<String,String> environment()
- Returns a string map view of this process builder's environment.
import java.io.File;
import java.util.Map;
public class Main{
public static void main(String args[]) {
try {
ProcessBuilder pb = new ProcessBuilder("myCommand", "myArg1", "myArg2");
Map<String, String> env = pb.environment();
env.put("VAR1", "myValue");
env.remove("anotherValue");
Process p = pb.start();
} catch (Exception e) {
System.out.println("Error executing notepad.");
}
}
}
Home
Java Book
Essential Classes
Java Book
Essential Classes
ProcessBuilder:
- ProcessBuilder class
- Create ProcessBuilder
- Get/set the working directory
- Get the environment variables
- Start a new process