Process.V2 may block with wrong way use of "process_stdio"
- Dominant language
- C++
- Stars
- 145
- Forks
- 151
- PR merge metrics
- No merged PRs in 30d
Description
```
#define WIN32_LEAN_AND_MEAN
#define BOOST_PROCESS_VERSION 2
#include
#include
#if defined(BOOST_PROCESS_V2_WINDOWS)
#pragma comment(lib,"ntdll.lib")
//for MSVC 143
#if defined(_MT) //MultiThread Static
# if defined(_DEBUG)
# pragma comment(lib,"libboost_process-vc143-mt-sgd-x64-1_87.lib")
# endif
#endif
#endif
using namespace boost;
namespace bp = boost::process::v2;
int main()
{
asio::io_context ctx;
std::string output;
output.resize(1000);
system::error_code ec;
{
//bad way
asio::readable_pipe rp2{ ctx };
//this io must declare inside proc like bp::process proc(ctx,xx,xxx,bp::process_stdio{{...},{...},{..}}}
bp::process_stdio io = bp::process_stdio{ nullptr, rp2, nullptr };
//due to process_io_binding@stdio.hpp hold this pip handle with a unique_ptr,
//this make the life time as long as the var 'proc' bellow
//and cannot clean the handle passed to the child,after CreateProcessW
//thus read_some can't get ERROR_PIPE_BROKEN(because there still have a valid PIPE handle in 'io')
//use SysinternalsSuite/procexp64 FIND->FIND Handle or DLL to search 'asio'
//after child process exit.it should not valid.
bp::process proc(ctx, R"(C:\Program Files\Git\bin\git.exe)", { "-v" }, io);
proc.detach();
while (true)
{
//bad:never revice ERROR_PIPE_BROKEN
auto size = rp2.read_some(asio::buffer(output), ec);
if (ec) break;
std::cout<
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.