From 126f5f4da74c476c9dfc59a4f45ded6c337cc635 Mon Sep 17 00:00:00 2001 From: Chaoqian Xu Date: Thu, 19 Dec 2024 14:27:31 +0800 Subject: [PATCH] feat(shell): add exit_status to get the child's exit status. --- plugins/shell/src/process/mod.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugins/shell/src/process/mod.rs b/plugins/shell/src/process/mod.rs index ac801834..0cca55c0 100644 --- a/plugins/shell/src/process/mod.rs +++ b/plugins/shell/src/process/mod.rs @@ -80,6 +80,13 @@ impl CommandChild { Ok(()) } + /// Return the child's exit status if it has already exited. If the child is + /// still running, return `Ok(None)`. + pub fn exit_status(&self) -> crate::Result> { + let status = self.inner.try_wait()?; + Ok(status.map(|s| ExitStatus { code: s.code() })) + } + /// Returns the process pid. pub fn pid(&self) -> u32 { self.inner.id()