Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for a snapshot of the master branch, built from commit 41728d1a0f.
PrevUpHomeNext

Struct process_environment

boost::process::v2::process_environment — Initializer for the environment of sub process.

Synopsis

// In header: <boost/process/v2/environment.hpp>


struct process_environment {
  // construct/copy/destruct
  process_environment(std::initializer_list< string_view >);
  template<typename Args> process_environment(Args &&);

  // public static functions
  template<typename Args> 
    static std::vector< const char * > 
    build_env(Args &&, 
              typename std::enable_if< std::is_convertible< decltype(*std::begin(std::declval< Args >())), cstring_ref >::value, 
              ::type * = nullptr);

  // public member functions
  template<typename Args> 
    std::vector< const char * > 
    build_env(Args &&, 
              typename std::enable_if< !std::is_convertible< decltype(*std::begin(std::declval< Args >())), cstring_ref >::value, 
              ::type * = nullptr);
  error_code on_setup(posix::default_launcher &, const filesystem::path &, 
                      const char *const *);

  // public data members
  std::vector< environment::key_value_pair > env_buffer;
  std::vector< const char * > env;
};

Description

This will set the environment in a subprocess:

process proc{executor, find_executable("printenv"), {"foo"}, process_environment{"foo=bar"}};

The environment initializer will persist it's state, so that it can be used multiple times. Do however note the the Operating System is allowed to modify the internal state.

auto exe = find_executable("printenv");
process_environment env = {"FOO=BAR", "BAR=FOO"};

process proc1(executor, exe, {"FOO"}, env);
process proc2(executor, exe, {"BAR"}, env);

process_environment public construct/copy/destruct

  1. process_environment(std::initializer_list< string_view > sv);
  2. template<typename Args> process_environment(Args && args);

process_environment public static functions

  1. template<typename Args> 
      static std::vector< const char * > 
      build_env(Args && args, 
                typename std::enable_if< std::is_convertible< decltype(*std::begin(std::declval< Args >())), cstring_ref >::value, 
                ::type * = nullptr);

process_environment public member functions

  1. template<typename Args> 
      std::vector< const char * > 
      build_env(Args && args, 
                typename std::enable_if< !std::is_convertible< decltype(*std::begin(std::declval< Args >())), cstring_ref >::value, 
                ::type * = nullptr);
  2. error_code on_setup(posix::default_launcher & launcher, 
                        const filesystem::path &, const char *const *);

PrevUpHomeNext