wait for child process

pull/1947/head
Ludea 9 months ago
parent cfd48b3b2e
commit e97e07d8da

@ -17,6 +17,7 @@ use crate::{
scope::ExecuteArgs,
Shell,
};
use std::process::ExitStatus;
type ChildId = u32;
@ -302,6 +303,20 @@ pub fn kill<R: Runtime>(
Ok(())
}
#[tauri::command]
pub fn wait<R: Runtime>(
_window: Window<R>,
shell: State<'_, Shell<R>>,
pid: ChildId,
) -> crate::Result<ExitStatus> {
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<R: Runtime>(
_window: Window<R>,

@ -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 {

@ -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<std::process::ExitStatus> {
let exitstatus = self.inner.wait()?;
Ok(exitstatus)
}
}
/// Describes the result of a process after it has terminated.

Loading…
Cancel
Save