Why boost :: process crash on windows when stderr is redirected to a pipe?

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?

+6
source share
1

Boost Process. include\boost\process\detail\windows\async_out.hpp , , :

arg.resize(buffer->size());
is.read(&*arg.begin(), buffer->size());

, std_err std_out. , . hostname.exe std_err, , pyw.exe, std_out.

progam , buffer->size() 0, . , ( ) Visual ++.

:

auto bufferSize = buffer->size();
if (bufferSize) {
    arg.resize(buffer->size());
    is.read(&*arg.begin(), buffer->size());
}

, , , .

+1

All Articles