[−][src]Struct shell_protocol::ProcessHandler
Structure to handle lifetime and communications with child process
Fields
stdout_reader: Option<BufReader<TimeoutReader<ChildStdout>>>
Buffered timeout reader pointed to stdout pipe
stderr_reader: Option<BufReader<TimeoutReader<ChildStderr>>>
Buffered timeout reader pointed to stderr pipe
Methods
impl ProcessHandler
[src]
pub fn spawn(
command: &str,
args: Option<Vec<String>>
) -> Result<ProcessHandler, ProtocolError>
[src]
command: &str,
args: Option<Vec<String>>
) -> Result<ProcessHandler, ProtocolError>
Spawn a process and setup handler structure
Arguments
- command - Path to binary to execute
- args - Optional arguments for binary
Examples
use shell_protocol::*; let proc = ProcessHandler::spawn(&"/bin/bash".to_owned(), None);
use shell_protocol::*; let proc = ProcessHandler::spawn(&"ls".to_owned(), Some(vec!["-l".to_owned()]));
pub fn read_stdout(&mut self) -> Result<Option<String>, ProtocolError>
[src]
Attempt to read from stdout
A return value of None
indicates the stream is
no longer available and likewise the process
is likely no longer alive.
Examples
use shell_protocol::*; let mut proc = ProcessHandler::spawn(&"ls".to_owned(), None).unwrap(); match proc.read_stdout() { Ok(Some(output)) => println!("Stdout: {}", output), Ok(None) => println!("Stdout time out"), Err(e) => eprintln!("Stdout err {}", e), }
pub fn read_stderr(&mut self) -> Result<Option<String>, ProtocolError>
[src]
Attempt to read from stderr
A return value of None
indicates the stream is
no longer available and likewise the process
is likely no longer alive.
Examples
use shell_protocol::*; let mut proc = ProcessHandler::spawn(&"ls".to_owned(), None).unwrap(); match proc.read_stderr() { Ok(Some(output)) => println!("Stderr: {}", output), Ok(None) => println!("Stderr time out"), Err(e) => eprintln!("Stderr err {}", e), }
pub fn write_stdin(&mut self, data: &[u8]) -> Result<(), ProtocolError>
[src]
Attempt to write to stdin
Arguments
- data - Slice of bytes to write
Examples
use shell_protocol::*; let cmd = "ls\n".as_bytes(); let mut proc = ProcessHandler::spawn(&"/bin/bash".to_owned(), None).unwrap(); match proc.write_stdin(&cmd) { Ok(()) => println!("Stdin write success"), Err(e) => eprintln!("Stdin err {}", e), }
pub fn close_stdin(&mut self) -> Result<(), ProtocolError>
[src]
Close process' stdin pipe
Examples
use shell_protocol::*; let mut proc = ProcessHandler::spawn(&"/bin/bash".to_owned(), None).unwrap(); match proc.close_stdin() { Ok(()) => println!("Stdin closed"), Err(e) => eprintln!("Stdin close err {}", e), }
pub fn id(&self) -> u32
[src]
Retrieve ID of process
Examples
use shell_protocol::*; let proc = ProcessHandler::spawn(&"/bin/bash".to_owned(), None).unwrap(); let pid = proc.id();
pub fn status(&mut self) -> Result<Option<(u32, u32)>, ProtocolError>
[src]
Check to see if a process has exited and if the exit status is available
Examples
use shell_protocol::*; let mut proc = ProcessHandler::spawn(&"/bin/bash".to_owned(), None).unwrap(); match proc.status() { Ok(Some((code, signal))) => println!("Process has exited: {}, {}", code, signal), Ok(None) => println!("Process has not exited"), Err(e) => eprintln!("Error getting process status {}", e) }
pub fn kill(&mut self, signal: Option<u32>) -> Result<(), ProtocolError>
[src]
Send killing signal to process
Arguments
- signal - Optional signal to send to process
Examples
use shell_protocol::*; let mut proc = ProcessHandler::spawn(&"/bin/bash".to_owned(), None).unwrap(); match proc.kill(None) { Ok(()) => println!("Process killed"), Err(e) => eprintln!("Error killing process: {}", e), }
Auto Trait Implementations
impl Send for ProcessHandler
impl Sync for ProcessHandler
Blanket Implementations
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>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,