[v2][Windows] Cannot redirect stdout to a file
- Dominant language
- C++
- Stars
- 145
- Forks
- 151
- PR merge metrics
- No merged PRs in 30d
Description
I am using boost process v2 from the 1.86 version of the boost library.
The following code is intended to redirect stdout to a file. It creates the file but the contents of stdout are not written to it; the file size is zero. When I redirect stdout to a pipe, the pipe contains the expected result.
I guessed at how to write the code to redirect stdout to a file, as I could not find any example in the documentation or online. So I have probably not done it right.
```
#include
#include
#include
#include
namespace proc = boost::process::v2;
namespace asio = boost::asio;
std::tuple execProc(const std::string& exePath, const std::vector& args,
const std::string& outputFilePath)
{
asio::io_context ctx;
asio::basic_stream_file outStream(ctx, outputFilePath.c_str(),
asio::file_base::write_only | asio::file_base::create | asio::file_base::exclusive);
asio::readable_pipe errPipe{ctx};
proc::process proc{ ctx, exePath, args, proc::process_stdio{{}, outStream, errPipe}};
std::string error;
boost::system::error_code ec;
auto errLen = asio::read(errPipe, asio::dynamic_buffer(error), ec);
auto exitCode = proc.wait();
outStream.close();
return std::make_tuple(exitCode, std::move(error));
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.