Compartilhar via


JavaSystem.Getenv Method

Definition

Overloads

Getenv()

Returns an unmodifiable string map view of the current system environment.

Getenv(String)

Gets the value of the specified environment variable.

Getenv()

Returns an unmodifiable string map view of the current system environment.

[Android.Runtime.Register("getenv", "()Ljava/util/Map;", "")]
public static System.Collections.Generic.IDictionary<string,string> Getenv ();
[<Android.Runtime.Register("getenv", "()Ljava/util/Map;", "")>]
static member Getenv : unit -> System.Collections.Generic.IDictionary<string, string>

Returns

the environment as a map of variable names to values

Attributes

Remarks

Returns an unmodifiable string map view of the current system environment. The environment is a system-dependent mapping from names to values which is passed from parent to child processes.

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

The returned map will never contain null keys or values. Attempting to 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 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 {@link 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.

Added in 1.5.

Java documentation for java.lang.System.getenv().

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

Getenv(String)

Gets the value of the specified environment variable.

[Android.Runtime.Register("getenv", "(Ljava/lang/String;)Ljava/lang/String;", "")]
public static string? Getenv (string name);
[<Android.Runtime.Register("getenv", "(Ljava/lang/String;)Ljava/lang/String;", "")>]
static member Getenv : string -> string

Parameters

name
String

the name of the environment variable

Returns

the string value of the variable, or null if the variable is not defined in the system environment

Attributes

Remarks

Gets the value of the specified environment variable. An environment variable is a system-dependent external named value.

If a security manager exists, its SecurityManager#checkPermission checkPermission method is called with a {@link RuntimePermission}("getenv."+name) permission. This may result in a SecurityException being thrown. If no exception is thrown the value of the variable name is returned.

"EnvironmentVSSystemProperties"><i>System properties</i> and <i>environment variables</i> are both conceptually mappings between names and values. Both mechanisms can be used to pass user-defined information to a Java process. Environment variables have a more global effect, because they are visible to all descendants of the process which defines them, not just the immediate Java subprocess. They can have subtly different semantics, such as case insensitivity, on different operating systems. For these reasons, environment variables are more likely to have unintended side effects. It is best to use system properties where possible. Environment variables should be used when a global effect is desired, or when an external system interface requires an environment variable (such as PATH).

On UNIX systems the alphabetic case of name is typically significant, while on Microsoft Windows systems it is typically not. For example, the expression System.getenv("FOO").equals(System.getenv("foo")) is likely to be true on Microsoft Windows.

Java documentation for java.lang.System.getenv(java.lang.String).

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