fix: let users decide what to wrap in child process command (#279)

This commit is contained in:
4t145 2025-06-24 15:26:43 +08:00 • committed by GitHub
commit 893969ac77
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -66,16 +66,25 @@ impl AsyncRead for TokioChildProcessOut {
}
impl TokioChildProcess {
/// Create a new Tokio child process with the given command.
///
/// # Manage the child process
/// You can also check these issue and pr for more information on how to manage the child process:
/// - [#156](https://github.com/modelcontextprotocol/rust-sdk/pull/156)
/// - [#253](https://github.com/modelcontextprotocol/rust-sdk/issues/253)
/// ```rust,ignore
/// #[cfg(unix)]
/// command_wrap.wrap(process_wrap::tokio::ProcessGroup::leader());
/// #[cfg(windows)]
/// command_wrap.wrap(process_wrap::tokio::JobObject);
/// ```
///
pub fn new(command: impl Into<TokioCommandWrap>) -> std::io::Result<Self> {
let mut command_wrap = command.into();
command_wrap
.command_mut()
.stdin(std::process::Stdio::piped())
.stdout(std::process::Stdio::piped());
#[cfg(unix)]
command_wrap.wrap(process_wrap::tokio::ProcessGroup::leader());
#[cfg(windows)]
command_wrap.wrap(process_wrap::tokio::JobObject);
let (child, (child_stdout, child_stdin)) = child_process(command_wrap.spawn()?)?;
Ok(Self {
child: ChildWithCleanup { inner: child },