19#if __has_include(<boost/process/v1/args.hpp>)
20#define BOOST_PROCESS_V1_HEADER(header) <boost/process/v1/header>
21#define BOOST_PROCESS_VERSION 1
23#define BOOST_PROCESS_V1_HEADER(header) <boost/process/header>
31#include BOOST_PROCESS_V1_HEADER(args.hpp)
32#include BOOST_PROCESS_V1_HEADER(child.hpp)
33#include BOOST_PROCESS_V1_HEADER(env.hpp)
34#include BOOST_PROCESS_V1_HEADER(error.hpp)
35#include BOOST_PROCESS_V1_HEADER(exe.hpp)
36#include BOOST_PROCESS_V1_HEADER(io.hpp)
37#include BOOST_PROCESS_V1_HEADER(pipe.hpp)
38#include BOOST_PROCESS_V1_HEADER(search_path.hpp)
39#include <fmt/ranges.h>
41namespace bp = boost::process;
49 std::vector<std::string>
const args;
61 std::string logger_, std::string input_file_,
78#if TRINITY_COMPILER == TRINITY_COMPILER_MICROSOFT
80#pragma warning(disable:4297)
90 bp::ipstream outStream;
91 bp::ipstream errStream;
92#if TRINITY_COMPILER == TRINITY_COMPILER_MICROSOFT
108 auto inputFile = Trinity::make_unique_ptr_with_deleter<&::fclose>(!
input_file.empty() ? fopen(
input_file.c_str(),
"rb") :
nullptr);
116 bp::exe = boost::filesystem::absolute(
executable).string(),
118 bp::env = bp::environment(boost::this_process::environment()),
119 bp::std_in = inputFile.get(),
120 bp::std_out = outStream,
121 bp::std_err = errStream,
128 bp::exe = boost::filesystem::absolute(
executable).string(),
130 bp::env = bp::environment(boost::this_process::environment()),
131 bp::std_in = bp::close,
132 bp::std_out = outStream,
133 bp::std_err = errStream,
144 std::future<void> stdOutReader = std::async(std::launch::async, [&]
147 while (std::getline(outStream, line,
'\n'))
149 std::erase(line,
'\r');
155 std::future<void> stdErrReader = std::async(std::launch::async, [&]
158 while (std::getline(errStream, line,
'\n'))
160 std::erase(line,
'\r');
205 std::string logger, std::string input_file,
bool secure)
208 std::move(executable), std::move(args), std::move(logger), std::move(input_file), secure);
213std::shared_ptr<AsyncProcessResult>
StartAsyncProcess(std::string executable, std::vector<std::string> args,
214 std::string logger, std::string input_file,
bool secure)
216 std::shared_ptr<AsyncProcessResultImplementation> handle = std::make_shared<AsyncProcessResultImplementation>(
217 std::move(executable), std::move(args), std::move(logger), std::move(input_file), secure);
219 handle->SetFuture(std::async(std::launch::async, [handle] {
return handle->StartProcess(); }));
227 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)
int32 StartProcess(std::string executable, std::vector< std::string > args, std::string logger, std::string input_file, bool secure)