ProcessBuilder.Environment Method

Definition

Returns a string map view of this process builder's environment.

[Android.Runtime.Register("environment", "()Ljava/util/Map;", "")]
public System.Collections.Generic.IDictionary<string,string>? Environment ();
[<Android.Runtime.Register("environment", "()Ljava/util/Map;", "")>]
member this.Environment : unit -> System.Collections.Generic.IDictionary<string, string>

Returns

this process builder's environment

Attributes

Remarks

Returns a string map view of this process builder's environment.

Whenever a process builder is created, the environment is initialized to a copy of the current process environment (see System#getenv()). Subprocesses subsequently started by this object's #start() method will use this map as their environment.

The returned object may be modified using ordinary java.util.Map Map operations. These modifications will be visible to subprocesses started via the #start() method. Two ProcessBuilder instances always contain independent process environments, so changes to the returned map will never be reflected in any other ProcessBuilder instance or the values returned by System#getenv System.getenv.

If the system does not support environment variables, an empty map is returned.

The returned map does not permit null keys or values. Attempting to insert or query the presence of a null key or value will throw a NullPointerException. Attempting to query the presence of a key or value which is not of type String will throw a ClassCastException.

The behavior of the returned map is system-dependent. A system may not allow modifications to environment variables or may forbid certain variable names or values. For this reason, attempts to modify the map may fail with UnsupportedOperationException or IllegalArgumentException if the modification is not permitted by the operating system.

Since the external format of environment variable names and values is system-dependent, there may not be a one-to-one mapping between them and Java's Unicode strings. Nevertheless, the map is implemented in such a way that environment variables which are not modified by Java code will have an unmodified native representation in the subprocess.

The returned map and its collection views may not obey the general contract of the Object#equals and Object#hashCode methods.

The returned map is typically case-sensitive on all platforms.

If a security manager exists, its SecurityManager#checkPermission checkPermission method is called with a RuntimePermission("getenv.*") permission. This may result in a SecurityException being thrown.

When passing information to a Java subprocess, system properties are generally preferred over environment variables.

Java documentation for java.lang.ProcessBuilder.environment().

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to