This code is based on boost::process1.65.1 samples with spelling errors:
#include <boost/process.hpp>
int main(int argc, char *argv[])
{
boost::asio::io_service ios;
std::future<std::vector<char>> output, error;
boost::process::child c("hostname.exe",
boost::process::std_out > output,
boost::process::std_err > boost::process::null,
ios);
ios.run();
c.wait();
if (output.valid())
{
auto processOutput = output.get();
processOutput.push_back('\0');
printf(processOutput.data());
}
if (error.valid())
{
auto processError = error.get();
processError.push_back('\0');
printf(processError.data());
}
return 0;
}
It works as expected. It starts hostname.exeand displays its output, i.e. e. the name of your computer network.
You probably see that the variable is errornot used. It is also logical to read stderr, it hostname.exedoesnβt even use it normally, a realistic child process, of course, can use it. It is trivial to simply replace boost::process::std_err > boost::process::nullwith boost::process::std_err > error. However, this leads to a failure. An error message will appear:
vector iterator not dereferencable
Does anyone know the reason and how to get around this error?
source
share