Java - Advanced

ProcessBuilder


Most implementations of the Java virtual machine run as a single process. A running JVM process can start new processes.


How does java create new process - using ProcessBuilder.


Starting a new process which uses the default working directory and environment is easy:

Process p = new ProcessBuilder("myCommand", "myArg").start();

Here is an example that starts a process with a modified working directory and environment:

ProcessBuilder pb = new ProcessBuilder("myCommand", "myArg1", "myArg2"); 
Map<String, String> env = pb.environment();
env.put("VAR1", "myValue"); env.remove("OTHERVAR"); 
env.put("VAR2", env.get("VAR1") + "suffix"); 
pb.directory(new File("myDir")); 
Process p = pb.start();



JMX


Reflection

Security

No comments:

Post a Comment