EOF to stdin when launching process asynchronously on macOS

Open
#531 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
38/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp

Research direction

Start by compiling and running the supplied C++ reproducer on macOS 15.6.1 with Boost 1.89.0; trigger r and observe std::cin after /bin/ls exits. Inspect the interaction between bp::process_stdio{nullptr}, asynchronous launch, and the parent stdin state. Done means subprocess completion no longer causes the input loop to see EOF while the reproducer still reports the child exit code.

Written by the indexing model from the issue text.

Description

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

#include <boost/process.hpp>
#include <boost/asio.hpp>
#include <cstdio>
#include <string>
#include <iostream>
#include <future>
#include <vector>

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

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

int main(int argc, char *argv[]) {
  std::vector<std::future<void>> 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
Dominant language
C++
Stars
145
Forks
151
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from boostorg/process

All issues in boostorg/process

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.