summaryrefslogtreecommitdiff
path: root/src/common/Utilities/StartProcess.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/Utilities/StartProcess.cpp')
-rw-r--r--src/common/Utilities/StartProcess.cpp21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/common/Utilities/StartProcess.cpp b/src/common/Utilities/StartProcess.cpp
index 7fbe053a8d..1da7817f41 100644
--- a/src/common/Utilities/StartProcess.cpp
+++ b/src/common/Utilities/StartProcess.cpp
@@ -70,7 +70,7 @@ namespace Acore
static int CreateChildProcess(T waiter, std::string const& executable,
std::vector<std::string> const& argsVector,
std::string const& logger, std::string const& input,
- bool secure)
+ bool secure, boost::process::environment envVariables = boost::this_process::environment())
{
ipstream outStream;
ipstream errStream;
@@ -97,7 +97,7 @@ namespace Acore
return child{
exe = std::filesystem::absolute(executable).string(),
args = argsVector,
- env = environment(boost::this_process::environment()),
+ env = environment(envVariables),
std_in = inputFile.get(),
std_out = outStream,
std_err = errStream
@@ -109,7 +109,7 @@ namespace Acore
return child{
exe = std::filesystem::absolute(executable).string(),
args = argsVector,
- env = environment(boost::this_process::environment()),
+ env = environment(envVariables),
std_in = boost::process::close,
std_out = outStream,
std_err = errStream
@@ -144,7 +144,7 @@ namespace Acore
}
int StartProcess(std::string const& executable, std::vector<std::string> const& args,
- std::string const& logger, std::string input_file, bool secure)
+ std::string const& logger, std::string input_file, bool secure, boost::process::environment env)
{
return CreateChildProcess([](child& c) -> int
{
@@ -157,7 +157,7 @@ namespace Acore
{
return EXIT_FAILURE;
}
- }, executable, args, logger, input_file, secure);
+ }, executable, args, logger, input_file, secure, env);
}
class AsyncProcessResultImplementation
@@ -168,6 +168,7 @@ namespace Acore
std::string const logger;
std::string const input_file;
bool const is_secure;
+ boost::process::environment envVariables;
std::atomic<bool> was_terminated;
@@ -177,10 +178,10 @@ namespace Acore
public:
explicit AsyncProcessResultImplementation(std::string executable_, std::vector<std::string> args_,
std::string logger_, std::string input_file_,
- bool secure)
+ bool secure, boost::process::environment env)
: executable(std::move(executable_)), args(std::move(args_)),
logger(std::move(logger_)), input_file(input_file_),
- is_secure(secure), was_terminated(false) { }
+ is_secure(secure), envVariables(env), was_terminated(false) { }
AsyncProcessResultImplementation(AsyncProcessResultImplementation const&) = delete;
AsyncProcessResultImplementation& operator= (AsyncProcessResultImplementation const&) = delete;
@@ -209,7 +210,7 @@ namespace Acore
my_child.reset();
return was_terminated ? EXIT_FAILURE : exitCode;
- }, executable, args, logger, input_file, is_secure);
+ }, executable, args, logger, input_file, is_secure, envVariables);
}
void SetFuture(std::future<int> result_)
@@ -245,10 +246,10 @@ namespace Acore
std::shared_ptr<AsyncProcessResult>
StartAsyncProcess(std::string executable, std::vector<std::string> args,
- std::string logger, std::string input_file, bool secure)
+ std::string logger, std::string input_file, bool secure, boost::process::native_environment env)
{
auto handle = std::make_shared<AsyncProcessResultImplementation>(
- std::move(executable), std::move(args), std::move(logger), std::move(input_file), secure);
+ std::move(executable), std::move(args), std::move(logger), std::move(input_file), secure, env);
handle->SetFuture(std::async(std::launch::async, [handle] { return handle->StartProcess(); }));
return handle;