boostorg / boostorg/process

EOF to stdin when launching process asynchronously on macOS

Open
#531 10 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
145
Forks
151
PR merge metrics
No merged PRs in 30d

Description

On macOS 15.6.1 M3 the program below exits due to EOF flag being raised on `std::cin` after subprocess finishes.
```cpp
#include
#include
#include
#include
#include
#include
#include

namespace asio = boost::asio;
namespace bp = boost::process::v2;

void runCommand(const std::string &cmd);

int main(int argc, char *argv[]) {
std::vector> tasks;
std::string line;
while(true) {
if (!std::getline(std::cin, line)) {
if (std::cin.eof()) {
break;
}
std::printf("Error reading input?\n");
std::cin.clear();
continue;
}

if (line == "r") {
tasks.push_back(std::async(std::launch::async, []() {
runCommand("/bin/ls");
}));
}
}

return 0;
}

void runCommand(const std::string &cmd) {
try {
std::printf("Running subprocess: %s\n", cmd.c_str());
asio::io_context ctx;
bp::process subProcess(ctx, cmd, {}, bp::process_stdio{nullptr});
subProcess.wait();

std::printf("Finished running subprocess with exit code %d\n", subProcess.exit_code());
} catch (const std::exception &ex) {
std::printf("Error running subprocess: %s\n", ex.what());
}
}
```

Compiler
```
Apple clang version 17.0.0 (clang-1700.0.13.5)
Target: arm64-apple-darwin24.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
```

Boos version (from vcpkg)
```
1.89.0
```

Example run:
```
boost-process git:(cpp-boost-process) ✗ ./build/main
r
Running subprocess: /bin/ls
CMakeLists.txt README.md build main.cpp vcpkg.json vcpkg_installed
Finished running subprocess with exit code 0
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.