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 new
and 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
<details> current
<pre><code> Answer the current environment for Smalltalk. This is equivalent to typing 'set' at a Windows shell prompt.
Answers:
<OsProcessEnvironment>
</code></pre> </details>
<details> new
<pre><code> Answer a new instance of the receiver. The new environment is empty.
Answers:
<OsProcessEnvironment>
</code></pre> </details>
<details> startUpEnvironment
<pre><code> Answer the startUp environment for the user process. This provides a snapshot of the environment that Smalltalk was run from.
Answers:
<OsProcessEnvironment>
</code></pre> </details>
Instance Methods
<details> asKeyedCollection
<pre><code> Answer the environment as keys and values in a keyed collection. The keys and values are encoded using the current code page.
Answers
<KeyedCollection>
</code></pre> </details>
<details> asUtf8KeyedCollection
<pre><code> Answer the environment values in the receiver.
Answers
<Collection>
</code></pre> </details>
<details> at:
<pre><code> 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
</code></pre> </details>
<details> at:ifAbsent:
<pre><code> 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
</code></pre> </details>
<details> at:put:
<pre><code> 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
</code></pre> </details>
<details> includesKey:
<pre><code> Answer a <Boolean> which is true if the the environment variable is present, false otherwise
Arguments:
aKey - <String> code page encoded
Asnwers:
<Boolean>
</code></pre> </details>
<details> keys
<pre><code> Answer the environment keys in the receiver. The keys are encoded using the current code page.
Answers
<Collection>
</code></pre> </details>
<details> removeKey:
<pre><code> 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
</code></pre> </details>
<details> utf8At:
<pre><code> 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
</code></pre> </details>
<details> utf8At:ifAbsent:
<pre><code> 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
</code></pre> </details>
<details> utf8At:put:
<pre><code> 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
</code></pre> </details>
<details> utf8IncludesKey:
<pre><code> Answer a <Boolean> which is true if the the environment variable is present, false otherwise
Arguments:
aKey - <String>
Asnwers:
<Boolean>
</code></pre> </details>
<details> utf8Keys
<pre><code> Answer the environment keys in the receiver.
Answers
<Collection>
</code></pre> </details>
<details> utf8RemoveKey:
<pre><code> 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
</code></pre> </details>
<details> utf8Values
<pre><code> Answer the environment values in the receiver.
Answers
<Collection>
</code></pre> </details>
<details> values
<pre><code> Answer the environment values in the receiver. The keys are encoded using the current code page.
Answers
<Collection>
</code></pre> </details>
Last modified date: 07/07/2022