[−][src]Struct subprocess::Communicator
Deadlock-free communication with the subprocess.
Normally care must be taken to avoid deadlock when communicating to a
subprocess that both expects input and provides output. This
implementation avoids deadlock by reading from and writing to the
subprocess in parallel. On Unix-like systems this is achieved using
poll(), and on Windows using threads.
Methods
impl Communicator[src]
pub fn read(
&mut self
) -> Result<(Option<Vec<u8>>, Option<Vec<u8>>), CommunicateError>[src]
&mut self
) -> Result<(Option<Vec<u8>>, Option<Vec<u8>>), CommunicateError>
Return the subprocess's output and error contents.
This will write the input data to the subprocess and read its output
and error in parallel, taking care to avoid deadlocks. The output and
error are returned as pairs of Option<Vec>, which can be None if
the corresponding stream has not been specified as
Redirection::Pipe.
By default read() will read all requested data.
If limit_time has been called, the method will read for no more than
the specified duration. In case of timeout, an error of kind
io::ErrorKind::TimedOut is returned. Communication may be resumed
after the timeout by calling read() again.
If limit_size has been called, the method will return no more than
the specified amount of bytes in the two vectors combined. (It might
internally read a bit more from the subprocess, but the data will
remain available for reading.) Subsequent data can be retrieved by
calling read() again. The primary use case for this method is
preventing a rogue subprocess from breaking the caller by spending all
its memory.
Panics
If input_data is provided and stdin was not redirected to a pipe.
Also, if input_data is not provided and stdin was redirected to a
pipe.
Errors
Err(CommunicateError)if a system call fails. In case of timeout, the underlying error kind will beErrorKind::TimedOut.
Regardless of the nature of the error, the content prior to the error
can be retrieved using the capture attribute of the error.
pub fn read_string(
&mut self
) -> Result<(Option<String>, Option<String>), CommunicateError>[src]
&mut self
) -> Result<(Option<String>, Option<String>), CommunicateError>
Return the subprocess's output and error contents as strings.
Like read(), but returns strings instead of byte vectors. Invalid
UTF-8 sequences, if found, are replaced with the the U+FFFD Unicode
replacement character.
pub fn limit_size(self, size: usize) -> Communicator[src]
Limit the amount of data the next read() will read from the
subprocess.
pub fn limit_time(self, time: Duration) -> Communicator[src]
Limit the amount of time the next read() will spend reading from the
subprocess.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Communicator
impl Send for Communicator
impl Sync for Communicator
impl Unpin for Communicator
impl UnwindSafe for Communicator
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,