2
0
mirror of https://github.com/boostorg/process.git synced 2026-02-02 21:12:14 +00:00

added example for modifying inherited environment.

This commit is contained in:
Klemens Morgenstern
2025-06-26 22:48:16 +08:00
parent 0c3c79672f
commit c72650df30
2 changed files with 47 additions and 0 deletions

View File

@@ -42,4 +42,30 @@ int main()
process pro2(ctx, exe, {"test.cpp"}, process_environment(my_env));
// end::subprocess_env[]
}
{
// tag::vector_env[]
asio::io_context ctx;
auto c = environment::current();
// a view is fine since the value is our value is static.
std::vector<environment::key_value_pair_view> my_env{c.begin(), c.end()};
my_env.push_back("SECRET=THIS_IS_A_TEST");
auto exe = environment::find_executable("g++", my_env);
process proc(ctx, exe, {"main.cpp"}, process_environment(my_env));
// end::vector_env[]
}
{
// tag::map_env[]
asio::io_context ctx;
std::unordered_map<environment::key, environment::value> my_env;
for (const auto & kv : environment::current())
if (kv.key() != "SECRET")
my_env[kv.key()] = kv.value();
auto exe = environment::find_executable("g++", my_env);
process proc(ctx, exe, {"main.cpp"}, process_environment(my_env));
// end::map_env[]
}
}