23#include <boost/process/args.hpp>
24#include <boost/process/child.hpp>
25#include <boost/process/env.hpp>
26#include <boost/process/exe.hpp>
27#include <boost/process/io.hpp>
28#include <boost/process/pipe.hpp>
29#include <boost/process/search_path.hpp>
30#include <fmt/ranges.h>
32namespace bp = boost::process;
40 std::vector<std::string>
const args;
52 std::string logger_, std::string input_file_,
69#if TRINITY_COMPILER == TRINITY_COMPILER_MICROSOFT
71#pragma warning(disable:4297)
81 bp::ipstream outStream;
82 bp::ipstream errStream;
83#if TRINITY_COMPILER == TRINITY_COMPILER_MICROSOFT
100 bp::exe = boost::filesystem::absolute(
executable).
string(),
102 bp::env = bp::environment(boost::this_process::environment()),
103 bp::std_in = inputFile.get(),
104 bp::std_out = outStream,
105 bp::std_err = errStream
111 bp::exe = boost::filesystem::absolute(
executable).
string(),
113 bp::env = bp::environment(boost::this_process::environment()),
114 bp::std_in = boost::process::close,
115 bp::std_out = outStream,
116 bp::std_err = errStream
120 std::future<void> stdOutReader = std::async(std::launch::async, [&]
123 while (std::getline(outStream, line,
'\n'))
125 std::erase(line,
'\r');
131 std::future<void> stdErrReader = std::async(std::launch::async, [&]
134 while (std::getline(errStream, line,
'\n'))
136 std::erase(line,
'\r');
185 std::string logger, std::string input_file,
bool secure)
188 std::move(executable), std::move(args), std::move(logger), std::move(input_file), secure);
193std::shared_ptr<AsyncProcessResult>
StartAsyncProcess(std::string executable, std::vector<std::string> args,
194 std::string logger, std::string input_file,
bool secure)
196 std::shared_ptr<AsyncProcessResultImplementation> handle = std::make_shared<AsyncProcessResultImplementation>(
197 std::move(executable), std::move(args), std::move(logger), std::move(input_file), secure);
199 handle->SetFuture(std::async(std::launch::async, [handle] {
return handle->StartProcess(); }));
207 return bp::search_path(filename).string();
#define TC_LOG_ERROR(filterType__, message__,...)
#define TC_LOG_INFO(filterType__, message__,...)
#define TC_LOG_TRACE(filterType__, message__,...)
std::optional< T > Optional
Optional helper class to wrap optional values within.
void SetFuture(std::future< int32 > result_)
AsyncProcessResultImplementation & operator=(AsyncProcessResultImplementation const &)=delete
std::vector< std::string > const args
std::string const executable
~AsyncProcessResultImplementation()=default
AsyncProcessResultImplementation(AsyncProcessResultImplementation &&)=delete
AsyncProcessResultImplementation(AsyncProcessResultImplementation const &)=delete
void Terminate() override
Tries to terminate the process.
std::atomic< bool > was_terminated
Optional< std::future< int > > futureResult
Optional< bp::child > my_child
AsyncProcessResultImplementation(std::string executable_, std::vector< std::string > args_, std::string logger_, std::string input_file_, bool secure)
std::future< int32 > & GetFutureResult() override
std::string const input_file
std::shared_ptr< AsyncProcessResult > StartAsyncProcess(std::string executable, std::vector< std::string > args, std::string logger, std::string input_file, bool secure)
std::string SearchExecutableInPath(std::string const &filename)
auto make_unique_ptr_with_deleter(T *ptr, Del &&deleter)
int StartProcess(std::string executable, std::vector< std::string > args, std::string logger, std::string input_file, bool secure)