diff --git a/src/lib.rs b/src/lib.rs index ed10784..cf005e1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -326,7 +326,7 @@ impl Child { /// } /// # std::io::Result::Ok(()) }); /// ``` - pub fn try_status(&mut self) -> io::Result> { + pub fn try_status(&self) -> io::Result> { self.child.lock().unwrap().get_mut().try_wait() } @@ -352,6 +352,30 @@ impl Child { /// ``` pub fn status(&mut self) -> impl Future> { self.stdin.take(); + self.status_no_drop() + } + + /// Waits for the process to exit. + /// + /// Unlike `status`, does not drop the stdin handle. You are responsible + /// for avoiding deadlocks caused by the child blocking on stdin while the + /// parent blocks on waiting for the process to exit. + /// + /// # Examples + /// + /// ```no_run + /// # futures_lite::future::block_on(async { + /// use async_process::{Command, Stdio}; + /// + /// let child = Command::new("cp") + /// .arg("a.txt") + /// .arg("b.txt") + /// .spawn()?; + /// + /// println!("exit status: {}", child.status_no_drop().await?); + /// # std::io::Result::Ok(()) }); + /// ``` + pub fn status_no_drop(&self) -> impl Future> { let child = self.child.clone(); async move {