15.7 Environment Variables
An environment variable set encapsulates a partial mapping from byte strings to bytes strings. A Racket process’s initial environment variable set is connected to the operating system’s environment variables: accesses or changes to the set read or change operating-system environment variables for the Racket process.
Since Windows environment variables are case-insensitive, and environment variable set’s key byte strings on Windows are case-folded. More precisely, key byte strings are coerced to a UTF-8 encoding of characters that are converted to lowercase via string-locale-downcase.
The current environment variable set, which is determined by the current-environment-variables parameter, is propagated to a subprocess when the subprocess is created.
procedure
v : any/c
parameter
(current-environment-variables env) → void? env : environment-variables?
procedure
v : any/c
procedure
(make-environment-variables name val ... ...)
→ environment-variables? name : bytes-environment-variable-name? val : bytes-no-nuls?
procedure
(environment-variables-ref env name)
→ (or/c #f (and/c bytes-no-nuls? immutable?)) env : environment-variables? name : bytes-environment-variable-name?
Normally, name should be a byte-string encoding of a string using the default encoding of the current locale. On Windows, name is coerced to a UTF-8 encoding and case-normalized.
procedure
(environment-variables-set! env name maybe-bstr [ fail]) → any env : environment-variables? name : bytes-environment-variable-name? maybe-bstr : (or/c bytes-no-nuls? #f)
fail : (-> any) =
(lambda () (raise (make-exn:fail ....)))
Normally, name and maybe-bstr should be a byte-string encoding of a string using the default encoding of the current locale. On Windows, name is coerced to a UTF-8 encoding and case-normalized, and maybe-bstr is coerced to a UTF-8 encoding if env is the initial environment variable set of the Racket process.
On success, the result of environment-variables-set! is #<void>. If env is the initial environment variable set of the Racket process, then attempting to adjust the operating system environment-variable mapping might fail for some reason, in which case fail is called in tail position with respect to the environment-variables-set!. The default fail raises an exception.
procedure
→ (listof (and/c bytes-environment-variable-name? immutable?)) env : environment-variables?
procedure
env : environment-variables?
procedure
(getenv name) → (or/c string-no-nuls? #f)
name : string-environment-variable-name?
procedure
name : string-environment-variable-name? value : string-no-nuls?
procedure
v : any/c