diff --git a/plugins/shell/src/commands.rs b/plugins/shell/src/commands.rs index 3345bb3a..ed043813 100644 --- a/plugins/shell/src/commands.rs +++ b/plugins/shell/src/commands.rs @@ -17,6 +17,7 @@ use crate::{ scope::ExecuteArgs, Shell, }; +use std::process::ExitStatus; type ChildId = u32; @@ -302,6 +303,20 @@ pub fn kill( Ok(()) } +#[tauri::command] +pub fn wait( + _window: Window, + shell: State<'_, Shell>, + pid: ChildId, +) -> crate::Result { + if let Some(child) = shell.children.lock().unwrap().get(&pid) { + let exitstatus: ExitStatus = child.wait()?; + Ok(exitstatus) + } else { + Err(crate::Error::UnknowChildProcess) + } +} + #[tauri::command] pub async fn open( _window: Window, diff --git a/plugins/shell/src/error.rs b/plugins/shell/src/error.rs index 652421b8..5ef03b81 100644 --- a/plugins/shell/src/error.rs +++ b/plugins/shell/src/error.rs @@ -33,6 +33,8 @@ pub enum Error { /// Utf8 error. #[error(transparent)] Utf8(#[from] std::string::FromUtf8Error), + #[error("Child process does'nt exist")] + UnknowChildProcess, } impl Serialize for Error { diff --git a/plugins/shell/src/process/mod.rs b/plugins/shell/src/process/mod.rs index 44f037b0..376eadc4 100644 --- a/plugins/shell/src/process/mod.rs +++ b/plugins/shell/src/process/mod.rs @@ -84,6 +84,12 @@ impl CommandChild { pub fn pid(&self) -> u32 { self.inner.id() } + + /// Waits for the child to exit completely, returning the status that it exited with. + pub fn wait(self) -> crate::Result { + let exitstatus = self.inner.wait()?; + Ok(exitstatus) + } } /// Describes the result of a process after it has terminated.