mirror of
https://github.com/boostorg/process.git
synced 2026-01-19 16:32:15 +00:00
53 lines
1.5 KiB
Plaintext
53 lines
1.5 KiB
Plaintext
== Environment
|
|
|
|
The `environment` namespace provides all sorts of facilities to query and manipulate the environment of the current process.
|
|
|
|
The api should be straight forward, but one oddity that needs to be pointed out is, that environment names
|
|
are not case sensitive on windows. The key_traits class implements the proper traits depending on the current system.
|
|
|
|
Additionally, environment can be lists separated by `:` or `;`; `environment::value` and
|
|
`environment::value_view` can be used to iterate those.
|
|
|
|
Beyond that, the requirements on an environment are a low as possible;
|
|
an environment is either a list of strings or a list of string-pairs. It is however recommended to use the environment types,
|
|
as to have the right value comparisons.
|
|
|
|
To note is the `find_executable` functions, which searches in an environment for an executable.
|
|
|
|
.example/env.cpp:19-28
|
|
[source,cpp]
|
|
----
|
|
include::../example/env.cpp[tag=current_env]
|
|
----
|
|
|
|
== Subprocess environment
|
|
|
|
The subprocess environment assignment follows the same constraints:
|
|
|
|
.example/env.cpp:34-42
|
|
[source,cpp,indent=0]
|
|
----
|
|
include::../example/env.cpp[tag=subprocess_env]
|
|
----
|
|
|
|
== Inheriting an environment
|
|
|
|
The current environment can be obtained by calling `environment::current` which returns
|
|
a forward range of `environment::key_value_pair_view`.
|
|
|
|
.example/env.cpp:48-54
|
|
[source,cpp,indent=0]
|
|
----
|
|
include::../example/env.cpp[tag=vector_env]
|
|
----
|
|
|
|
Alternatively you can use a map container for the environment.
|
|
|
|
.example/env.cpp:61-68
|
|
[source,cpp,indent=0]
|
|
----
|
|
include::../example/env.cpp[tag=map_env]
|
|
----
|
|
|
|
|