[ Operating System | Reference Manual | Alphabetic Index ]

setenv(+Name, +Value)

Sets the environment variable Name to the given value
Name
String or atom.
Value
String, atom or number.

Description

The first argument must be a string or an atom and is taken as the name of an operating system environment variable. The value of this environment variable is set, or changed to, the new value Value.

When Value is an atom or number, it is first converted to a string, and the environment variable is set to the resulting string value.

The mechanism can be used to pass information from an eclipse-process to its sub-processes. Note however, that due to operating system limitations, environment strings cannot contain null characters (unlike ECLiPSe strings). Also, the strings used as arguments to setenv/2 cannot be garbage collected and will accumulate.

Operating system dependencies: Because of portability issues, on UNIX there is currently no facility to unset an environment variable completely, but it can set to an empty string. On Windows on the other hand, an environment variable's value cannot be the empty string: setting an environment variable to the empty string makes it indistinguishable from an unset or nonexisting one.

Modes and Determinism

Exceptions

(4) instantiation fault
Name or Value is not instantiated.
(5) type error
Name is instantiated, but not to a string or an atom.
(5) type error
Value is instantiated, but not to a string, atom or number.
(170) system interface error
The environment could not be changed

Examples

   ?- setenv(abc, hello), getenv(abc, X).
   X = "hello"
   Yes (0.00s cpu)

   ?- setenv("abc", "world"), getenv(abc, X).
   X = "world"
   Yes (0.00s cpu)

   ?- setenv(abc, 999), getenv(abc, X).
   X = "999"
   Yes (0.00s cpu)

   ?-  setenv(abc, data), sh("echo $abc").
   data
   Yes (0.00s cpu)

   ?- setenv(abc, data), exec([sh,"-c","echo $abc"], []).
   data
   Yes (0.00s cpu)

   ?- setenv(abc, data), exec([eclipse,"-e","getenv(abc,X),writeln(X)"], []).
   data
   Yes (0.00s cpu)

   ?- setenv(abc, ""), getenv(abc, X).	% on UNIX
   X = ""
   Yes (0.00s cpu)

   ?- setenv(abc, ""), getenv(abc, X).	% on Windows
   No (0.00s cpu)

See Also

exec / 2, exec / 3, getenv / 2, sh / 1