Files
codex/codex-rs/utils/pty/src/child.rs
Charlie Marsh d086e2752d Move local child-process spawning into codex-utils-pty (#46659)
## What changed

Expose the shared `Child` type and `spawn_child` function from `codex-utils-pty`, and update the MCP stdio transport to use them. Move the existing macOS spawning implementation and its tests into the utility crate, preserving platform-specific spawning, piped stdio, and kill-on-drop behavior.

GitOrigin-RevId: 26c2fb2f22cdba907aa9d18cab7dc8c4ac1c909e
2026-09-19 15:13:59 +00:00

35 lines
850 B
Rust

//! Uniform child-process API for local subprocesses, with platform-specific spawning.
//!
//! Commands must use the launcher's cleared environment, process group, and default
//! argv[0]. Both implementations expose Tokio stdio handles and kill on drop.
use std::io;
use std::process::Stdio;
use tokio::process::Command;
#[cfg(target_os = "macos")]
#[path = "macos_child.rs"]
mod macos;
#[cfg(target_os = "macos")]
pub use macos::Child;
#[cfg(not(target_os = "macos"))]
pub use tokio::process::Child;
pub fn spawn(mut command: Command) -> io::Result<Child> {
command
.kill_on_drop(true)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped());
#[cfg(target_os = "macos")]
{
Child::spawn(command)
}
#[cfg(not(target_os = "macos"))]
{
command.spawn()
}
}