pub struct NativeProcess { /* private fields */ }Expand description
A cross-platform child process with optional output capture.
NativeProcess wraps std::process::Command with the crate’s
process-tree containment, capture draining, timeout, and terminal-control
behavior. Methods are synchronous and are safe to call from ordinary
blocking code.
Implementations§
Source§impl NativeProcess
impl NativeProcess
Sourcepub fn new(config: ProcessConfig) -> Self
pub fn new(config: ProcessConfig) -> Self
Create a process wrapper from a ProcessConfig.
The child is not spawned until Self::start is called.
Sourcepub fn start(&self) -> Result<(), ProcessError>
pub fn start(&self) -> Result<(), ProcessError>
Spawn the configured child process.
Returns ProcessError::AlreadyStarted if the same wrapper already
owns a running child.
Sourcepub fn write_stdin(&self, data: &[u8]) -> Result<(), ProcessError>
pub fn write_stdin(&self, data: &[u8]) -> Result<(), ProcessError>
Write bytes to the child’s stdin and then close stdin.
Sourcepub fn write_stdin_streaming(&self, data: &[u8]) -> Result<(), ProcessError>
pub fn write_stdin_streaming(&self, data: &[u8]) -> Result<(), ProcessError>
Write to the child’s stdin without closing it afterwards, so the caller can issue additional writes. Used by interactive pipe-backed sessions (#130 milestone 3) where the daemon keeps stdin open across multiple client input frames.
Sourcepub fn close_stdin(&self) -> Result<(), ProcessError>
pub fn close_stdin(&self) -> Result<(), ProcessError>
Explicitly close the child’s stdin (signals EOF to the child). Idempotent: returns Ok if stdin was already closed.
Sourcepub fn poll(&self) -> Result<Option<i32>, ProcessError>
pub fn poll(&self) -> Result<Option<i32>, ProcessError>
Check whether the child has exited without blocking.
Returns Ok(None) while the process is still running.
Sourcepub fn wait(&self, timeout: Option<Duration>) -> Result<i32, ProcessError>
pub fn wait(&self, timeout: Option<Duration>) -> Result<i32, ProcessError>
Wait for the child to exit.
When timeout is Some, returns ProcessError::Timeout if the
child does not exit before the duration elapses.
Sourcepub fn kill(&self) -> Result<(), ProcessError>
pub fn kill(&self) -> Result<(), ProcessError>
Forcefully terminate the child process.
Sourcepub fn terminate(&self) -> Result<(), ProcessError>
pub fn terminate(&self) -> Result<(), ProcessError>
Terminate the child process.
This currently uses the same hard-kill path as Self::kill.
Sourcepub fn terminate_group_soft(&self) -> Result<(), ProcessError>
pub fn terminate_group_soft(&self) -> Result<(), ProcessError>
Send the OS-appropriate soft termination signal to the child’s
process group (POSIX: SIGTERM to -pid; Windows: no soft path
implemented yet — returns Ok without doing anything so callers
can run the same code on both platforms and rely on the post-
grace hard kill).
Requires ProcessConfig.create_process_group=true on POSIX so
that -pid resolves to the child’s own group. With the default
create_process_group=false, the kill would walk back to the
caller’s group; the method silently no-ops in that case to avoid
signaling the wrong tree.
Used by the daemon-side pipe sessions (#130 M4 follow-up) so
that TerminationOutcome::SoftExit becomes meaningful on POSIX.
Sourcepub fn close(&self) -> Result<(), ProcessError>
pub fn close(&self) -> Result<(), ProcessError>
Close the process wrapper by terminating the child when it is running.
Sourcepub fn pid(&self) -> Option<u32>
pub fn pid(&self) -> Option<u32>
Return the child process id when the wrapper currently owns a child.
Sourcepub fn returncode(&self) -> Option<i32>
pub fn returncode(&self) -> Option<i32>
Return the cached exit code when the child has exited.
Sourcepub fn has_pending_stream(&self, stream: StreamKind) -> bool
pub fn has_pending_stream(&self, stream: StreamKind) -> bool
Return whether captured output is queued for one stream.
Sourcepub fn has_pending_combined(&self) -> bool
pub fn has_pending_combined(&self) -> bool
Return whether captured combined output is queued.
Sourcepub fn drain_stream(&self, stream: StreamKind) -> Vec<Vec<u8>>
pub fn drain_stream(&self, stream: StreamKind) -> Vec<Vec<u8>>
Drain and return all queued output for one stream.
Sourcepub fn drain_combined(&self) -> Vec<StreamEvent>
pub fn drain_combined(&self) -> Vec<StreamEvent>
Drain and return all queued combined output events.
Sourcepub fn read_stream(
&self,
stream: StreamKind,
timeout: Option<Duration>,
) -> ReadStatus<Vec<u8>>
pub fn read_stream( &self, stream: StreamKind, timeout: Option<Duration>, ) -> ReadStatus<Vec<u8>>
Read the next captured chunk from one stream.
Returns ReadStatus::Timeout when timeout elapses before output or
EOF is observed.
Sourcepub fn read_combined(
&self,
timeout: Option<Duration>,
) -> ReadStatus<StreamEvent>
pub fn read_combined( &self, timeout: Option<Duration>, ) -> ReadStatus<StreamEvent>
Read the next captured combined stream event.
Sourcepub fn captured_stdout(&self) -> Vec<Vec<u8>>
pub fn captured_stdout(&self) -> Vec<Vec<u8>>
Return the retained stdout history.
Sourcepub fn captured_stderr(&self) -> Vec<Vec<u8>>
pub fn captured_stderr(&self) -> Vec<Vec<u8>>
Return the retained stderr history.
Sourcepub fn captured_combined(&self) -> Vec<StreamEvent>
pub fn captured_combined(&self) -> Vec<StreamEvent>
Return the retained combined stdout/stderr event history.
Sourcepub fn captured_stream_bytes(&self, stream: StreamKind) -> usize
pub fn captured_stream_bytes(&self, stream: StreamKind) -> usize
Return the retained byte count for one captured stream.
Sourcepub fn captured_combined_bytes(&self) -> usize
pub fn captured_combined_bytes(&self) -> usize
Return the retained byte count for combined captured output.
Sourcepub fn clear_captured_stream(&self, stream: StreamKind) -> usize
pub fn clear_captured_stream(&self, stream: StreamKind) -> usize
Clear retained output history for one stream and return freed bytes.
Sourcepub fn clear_captured_combined(&self) -> usize
pub fn clear_captured_combined(&self) -> usize
Clear retained combined output history and return freed bytes.
Auto Trait Implementations§
impl Freeze for NativeProcess
impl RefUnwindSafe for NativeProcess
impl Send for NativeProcess
impl Sync for NativeProcess
impl Unpin for NativeProcess
impl UnsafeUnpin for NativeProcess
impl UnwindSafe for NativeProcess
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more