pub struct NativeOutputCapture { /* private fields */ }Expand description
An owned reader of a native child stdout/stderr pipe, with bounded byte retention.
Unix read ends use nonblocking I/O; Windows read ends use owned overlapped I/O.
Cancellation wakes the private reader; no user callbacks run
on it. cancel, finish_within and Drop all join
the reader and close its pipe, even when a descendant keeps the write end open. Idle
readers check the pipe every 20 ms; cancellation also wakes that wait immediately.
This guarantee cannot be provided for arbitrary Read; use crate::OutputCapture
only when the reader’s lifetime is controlled separately. Do not change the native
read end’s blocking mode through another handle while this capture owns it.
Windows requires a byte pipe opened for overlapped I/O (including OwnedCommand pipes);
disconnected overlapped pipes are accepted as EOF without issuing a read.
Construction rejects unsupported handles before starting a reader.
Implementations§
Source§impl NativeOutputCapture
impl NativeOutputCapture
Sourcepub fn stdout(pipe: ChildStdout, max_bytes: usize) -> Result<Self>
pub fn stdout(pipe: ChildStdout, max_bytes: usize) -> Result<Self>
Own & drain a child’s stdout. Errors before spawning a reader if the pipe cannot support cancellable native I/O or the operating system cannot start the reader thread.
Sourcepub fn stderr(pipe: ChildStderr, max_bytes: usize) -> Result<Self>
pub fn stderr(pipe: ChildStderr, max_bytes: usize) -> Result<Self>
Own & drain a child’s stderr, with the same guarantees as stdout.
Sourcepub fn snapshot(&self) -> CapturedOutput
pub fn snapshot(&self) -> CapturedOutput
What has been captured so far. This does not stop the reader.
Sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
True only if the pipe reached EOF. A deadline/cancellation can return partial bytes
without exceeding the retention cap; CapturedOutput::truncated describes cap loss.
Sourcepub fn take_error(&self) -> Option<Error>
pub fn take_error(&self) -> Option<Error>
Take the native read error, if any. Cancellation is not an error.
Sourcepub fn finish_within(&mut self, timeout: Duration) -> CapturedOutput
pub fn finish_within(&mut self, timeout: Duration) -> CapturedOutput
Wait up to timeout for EOF/error, then cancel & join the reader. Always closes the
read end before returning; a writer retained by a descendant cannot extend the wait.
Returned bytes may be partial: consult is_complete.
Sourcepub fn cancel(&mut self) -> CapturedOutput
pub fn cancel(&mut self) -> CapturedOutput
Cancel immediately, join the reader & return retained bytes. Idempotent.