Process process(options.Combine(), "", [](const char *bytes, size_t n) {
std::cout << "xxyy" << std::string(bytes, n) << "yyxx" << std::endl;
}, [](const char *bytes, size_t n) {
std::cout << "xxyy" << std::string(bytes, n) << "yyxx" << std::endl;
});
....
BOOL bSuccess = CreateProcess(nullptr, process_command.empty()?nullptr:&process_command[0], nullptr, nullptr, TRUE, 0,
nullptr, path.empty()?nullptr:path.c_str(), &startup_info, &process_info);
if(!bSuccess) {
CloseHandle(process_info.hProcess);
CloseHandle(process_info.hThread);
return 0; // here it stops and doesn't proceed to fire the lambda's to capture output
}
else {
CloseHandle(process_info.hThread);
}
if(stdin_fd) *stdin_fd=stdin_wr_p.detach();
if(stdout_fd) *stdout_fd=stdout_rd_p.detach();
if(stderr_fd) *stderr_fd=stderr_rd_p.detach();
....
Fire the lambda's with captured output either way (even if bSuccess == false). It's the callers responsibility to check the exit code anyway, and a separate "binary doesn't exist" code can be emitted.