mirror of
https://github.com/boostorg/process.git
synced 2026-02-21 15:22:11 +00:00
48 lines
1.7 KiB
Plaintext
48 lines
1.7 KiB
Plaintext
[section:env 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 recommented 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.
|
|
|
|
```
|
|
// search in the current environment
|
|
auto exe = environment::find_executable("g++");
|
|
|
|
std::unordered_map<environment::key, environment::value> my_env =
|
|
{
|
|
{"SECRET", "THIS_IS_A_TEST"}
|
|
{"PATH", {"/bin", "/usr/bin"}
|
|
};
|
|
|
|
auto other_exe = environment::find_executable("g++", my_env);
|
|
```
|
|
|
|
[section:process_env Subprocess environment]
|
|
|
|
The subprocess environment assignment follows the same constraints:
|
|
|
|
```
|
|
asio::io_context ctx;
|
|
std::unordered_map<environment::key, environment::value> my_env =
|
|
{
|
|
{"SECRET", "THIS_IS_A_TEST"}
|
|
{"PATH", {"/bin", "/usr/bin"}
|
|
};
|
|
auto exe = find_executable("g++"), my_env);
|
|
process proc(ctx, exe, {"main.cpp"}, process_environment(my_env));
|
|
process pro2(ctx, exe, {"test.cpp"}, process_environment(my_env));
|
|
```
|
|
|
|
[endsect]
|
|
|
|
[endsect] |