Java ProcessBuilder.environment()

Syntax

ProcessBuilder.environment() has the following syntax.

public Map <String , String> environment()

Example

In the following code shows how to use ProcessBuilder.environment() method.


/*w w w .  jav a 2 s  . c  o m*/

import java.util.Map;

public class Main {

   public static void main(String[] args) {

      // create a new list of arguments for our process
      String[] list = {"notepad.exe", "test.txt"};

      // create the process builder
      ProcessBuilder pb = new ProcessBuilder(list);

      // get the environment of the process
      Map<String, String>  env = pb.environment();

      // get the system drive of the environment
      System.out.println(env);
      System.out.println(env.get("SystemDrive"));
   }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable