pub struct ProcessHandle { /* private fields */ }Expand description
Handle for driving an interactive or non-interactive process.
This provides a unified interface for both PTY and pipe-based processes:
- Write to stdin via
writer_sender() - Read merged stdout/stderr via
output_receiver() - Check exit status via
has_exited()andexit_code() - Clean up via
terminate()
Implementations§
Source§impl ProcessHandle
impl ProcessHandle
Sourcepub fn new(
writer_tx: Sender<Vec<u8>>,
output_tx: Sender<Vec<u8>>,
initial_output_rx: Receiver<Vec<u8>>,
killer: Box<dyn ChildTerminator>,
reader_handle: JoinHandle<()>,
reader_abort_handles: Vec<AbortHandle>,
writer_handle: JoinHandle<()>,
wait_handle: JoinHandle<()>,
exit_status: Arc<AtomicBool>,
exit_code: Arc<StdMutex<Option<i32>>>,
pty_handles: Option<PtyHandles>,
) -> (Self, Receiver<Vec<u8>>)
pub fn new( writer_tx: Sender<Vec<u8>>, output_tx: Sender<Vec<u8>>, initial_output_rx: Receiver<Vec<u8>>, killer: Box<dyn ChildTerminator>, reader_handle: JoinHandle<()>, reader_abort_handles: Vec<AbortHandle>, writer_handle: JoinHandle<()>, wait_handle: JoinHandle<()>, exit_status: Arc<AtomicBool>, exit_code: Arc<StdMutex<Option<i32>>>, pty_handles: Option<PtyHandles>, ) -> (Self, Receiver<Vec<u8>>)
Create a new process handle with all required components.
Sourcepub fn writer_sender(&self) -> Sender<Vec<u8>>
pub fn writer_sender(&self) -> Sender<Vec<u8>>
Sourcepub fn output_receiver(&self) -> Receiver<Vec<u8>>
pub fn output_receiver(&self) -> Receiver<Vec<u8>>
Returns a broadcast receiver that yields stdout/stderr chunks.
Multiple receivers can be created; each receives all output from the point of subscription.
Sourcepub fn has_exited(&self) -> bool
pub fn has_exited(&self) -> bool
True if the child process has exited.
Sourcepub fn terminate(&self)
pub fn terminate(&self)
Attempts to kill the child and abort helper tasks.
This is idempotent and safe to call multiple times.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Check if the process is still running.
Sourcepub async fn write(
&self,
bytes: impl Into<Vec<u8>>,
) -> Result<(), SendError<Vec<u8>>>
pub async fn write( &self, bytes: impl Into<Vec<u8>>, ) -> Result<(), SendError<Vec<u8>>>
Send bytes to the process stdin.
Returns an error if the stdin channel is closed.
Sourcepub fn is_writer_closed(&self) -> bool
pub fn is_writer_closed(&self) -> bool
Check if the writer channel is closed.
Trait Implementations§
Source§impl Debug for ProcessHandle
impl Debug for ProcessHandle
Auto Trait Implementations§
impl !Freeze for ProcessHandle
impl RefUnwindSafe for ProcessHandle
impl Send for ProcessHandle
impl Sync for ProcessHandle
impl Unpin for ProcessHandle
impl UnwindSafe for ProcessHandle
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
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
Converts
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>
Converts
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