OsProcessEnvironment
Description
Provides abstraction for cross-platform process environment (i.e. environment variables). Exposes a limited <KeyedCollection> interface for accessing, adding, removing env variables Examples below
Startup Environment
On Startup, the environment is cached and can be accessed with OsProcessEnvironment startUpEnvironment
Current Environment
You can request the current environment (lazily cached) with OsProcessEnvironment current. The current environment is special in that changes to it will be reflected in the underlying OS.
New Environment
Environments can be created simply with OsProcessEnvironment newand passed to new spawned processes
Examples
"Example: Custom Environment"
| process starter str |
 
"List Environment keys"
starter := OsProcessStarter new
command: #('cmd.exe' '/C' 'set');
environment: Dictionary new.
process := starter start.
process waitForCompletion.
str := (process outputStream tryNext: 1000) trimSeparators.
 
"Add an environment key"
starter environment at: 'MyKey' put: 'MyValue'.
process := starter start.
process waitForCompletion.
str := (process outputStream tryNext: 1000) trimSeparators.
Class Methods
current
  Answer the current environment for Smalltalk.
     This is equivalent to typing 'set' at a Windows shell prompt.

     Answers:
        <OsProcessEnvironment>
new
  Answer a new instance of the receiver. The new environment is empty.

     Answers:
        <OsProcessEnvironment>
startUpEnvironment
  Answer the startUp environment for the user process. This
     provides a snapshot of the environment that Smalltalk
     was run from.

     Answers:
        <OsProcessEnvironment>
Instance Methods
asKeyedCollection
  Answer the environment as keys and values in a keyed collection.
     The keys and values are encoded using the current code page.

     Answers
        <KeyedCollection>
asUtf8KeyedCollection
  Answer the environment values in the receiver.

     Answers
        <Collection>
at:
  Answer the environment value at key @aKey
     If an equivalent key is not found, then answer nil

     Arguments:
        aKey - <String> code page encoded env key
     Answers:
        <String> code page encoded env value
        <UndefinedObject> if absent key, then answer nil
at:ifAbsent:
  Answer the environment value at key @aKey
     If an equivalent key is not found, then answer the result
     of evaluating the zero argument block, aBlock.

     Fail if the key is not found and aBlock is not a zero-argument Block.

     NOTE: aKey is expected to be encoded using the current code page.
     Internally it will be stored in UTF-8 format.
     Use the utf8* APIs to work more directly with UTF-8 bytes

     Arguments:
        aKey - <String | ByteArray> code page encoded env key
        aBlock - <Block> 0-arg block
     Answers:
        <String | ByteArray> code page encoded env value
        <Object> if absent key, then answer the result of @aBlock evaluation
at:put:
  Answer the value currently associated with aKey (or nil if absent),
     after associating the argument aValue with the
     argument aKey, in the receiver.  
     If the receiver does not
     contain a key equivalent to the argument aKey, then create a new entry
     in the receiver for that key.
     If @aValue is nil, then remove the environment variable entry

     NOTE: If the receiver is the Current environement, then push this change
     out to the operating system also

     Arguments:
        aKey - <String | ByteArray>
        aValue - <String | ByteArray> or nil if removing the entry
     Asnwers:
        <String | ByteArray> or nil if there was no old value
includesKey:
  Answer a <Boolean> which is true if the the environment variable is present,
     false otherwise

     Arguments:
        aKey - <String> code page encoded
     Asnwers:
        <Boolean>
keys
  Answer the environment keys in the receiver.
     The keys are encoded using the current code page.

     Answers
        <Collection>
removeKey:
  Answer the value currently associated with aKey (or nil if absent),
     after removing the key @aKey
     If the receiver does not contain a key equivalent to the argument aKey, then create a new entry

     NOTE: If the receiver is the Current environement, then push this change
     out to the operating system also.  It will be in UTF-8 format in the OS

     Arguments:
        aKey - <String> code page encoded
     Asnwers:
        <String> code page encoded str or nil if there was no old value
utf8At:
  Answer the UTF-8 environment value at UTF-8 key @aUtf8Key
     If an equivalent key is not found, then answer nil

     Arguments:
        aUtf8Key - <String | ByteArray> env key
     Answers:
        <String | ByteArray> env value
        <Object> if absent key, then answer the result of @aBlock evaluation
utf8At:ifAbsent:
  Answer the UTF-8 environment value at UTF-8 key @aUtf8Key
     If an equivalent key is not found, then answer the result
     of evaluating the zero argument block, aBlock.

     Fail if the key is not found and aBlock is not a zero-argument Block.

     Arguments:
        aUtf8Key - <String | ByteArray> env key
        aBlock - <Block> 0-arg block
     Answers:
        <String | ByteArray> env value
        <Object> if absent key, then answer the result of @aBlock evaluation
utf8At:put:
  Answer the value currently associated with the UTF-8 @aUtf8Key (or nil if absent),
     after associating the UTF-8 argument @aUtf8Value with the
     aUtf8Key, in the receiver.  
     If the receiver does not
     contain a key equivalent to the argument aUtf8Key, then create a new entry
     in the receiver for that key.
     If @aUtf8Value is nil, then remove the environment variable entry

     NOTE: If the receiver is the Current environment, then push this change
     out to the operating system also

     Arguments:
        aKey - <String | ByteArray>
        aValue - <String ByteArray> or nil if removing the entry
     Asnwers:
        <String | ByteArray> or nil if there was no old value
utf8IncludesKey:
  Answer a <Boolean> which is true if the the environment variable is present,
     false otherwise

     Arguments:
        aKey - <String>
     Asnwers:
        <Boolean>
utf8Keys
  Answer the environment keys in the receiver.

     Answers
        <Collection>
utf8RemoveKey:
  Answer the value currently associated with aKey (or nil if absent),
     after removing the key @aKey
     If the receiver does not contain a key equivalent to the argument aKey, then create a new entry

     NOTE: If the receiver is the Current environement, then push this change
     out to the operating system also

     Arguments:
        aKey - <String>
     Asnwers:
        <String> or nil if there was no old value
utf8Values
  Answer the environment values in the receiver.

     Answers
        <Collection>
values
  Answer the environment values in the receiver.
     The keys are encoded using the current code page.

     Answers
        <Collection>
Last modified date: 07/07/2022