[−][src]Struct rexpect::process::PtyProcess
Start a process in a forked tty so you can interact with it the same as you would within a terminal
The process and pty session are killed upon dropping PtyProcess
Example
Typically you want to do something like this (for a more complete example see
unit test test_cat
within this module):
extern crate nix; extern crate rexpect; use rexpect::process::PtyProcess; use std::process::Command; use std::fs::File; use std::io::{BufReader, LineWriter}; use std::os::unix::io::{FromRawFd, AsRawFd}; use nix::unistd::dup; let mut process = PtyProcess::new(Command::new("cat")).expect("could not execute cat"); let fd = dup(process.pty.as_raw_fd()).unwrap(); let f = unsafe { File::from_raw_fd(fd) }; let mut writer = LineWriter::new(&f); let mut reader = BufReader::new(&f); process.exit().expect("could not terminate process"); // writer.write() sends strings to `cat` // writer.reader() reads back what `cat` wrote // send Ctrl-C with writer.write(&[3]) and writer.flush()
Fields
pty: PtyMaster
child_pid: Pid
Implementations
impl PtyProcess
[src]
pub fn new(command: Command) -> Result<Self>
[src]
Start a process in a forked pty
pub fn get_file_handle(&self) -> File
[src]
Get handle to pty fork for reading/writing
pub fn set_kill_timeout(&mut self, timeout_ms: Option<u64>)
[src]
At the drop of PtyProcess the running process is killed. This is blocking forever if
the process does not react to a normal kill. If kill_timeout is set the process is
kill -9
ed after duration
pub fn status(&self) -> Option<WaitStatus>
[src]
Get status of child process, nonblocking.
This method runs waitpid on the process.
This means: If you ran exit()
before or status()
this method will
return None
Example
use rexpect::process::{self, wait::WaitStatus}; use std::process::Command; let cmd = Command::new("/path/to/myprog"); let process = process::PtyProcess::new(cmd).expect("could not execute myprog"); while let Some(WaitStatus::StillAlive) = process.status() { // do something }
pub fn wait(&self) -> Result<WaitStatus>
[src]
Wait until process has exited. This is a blocking call. If the process doesn't terminate this will block forever.
pub fn exit(&mut self) -> Result<WaitStatus>
[src]
Regularly exit the process, this method is blocking until the process is dead
pub fn signal(&mut self, sig: Signal) -> Result<()>
[src]
Nonblocking variant of kill()
(doesn't wait for process to be killed)
pub fn kill(&mut self, sig: Signal) -> Result<WaitStatus>
[src]
Kill the process with a specific signal. This method blocks, until the process is dead
repeatedly sends SIGTERM to the process until it died, the pty session is closed upon dropping PtyMaster, so we don't need to explicitely do that here.
if kill_timeout
is set and a repeated sending of signal does not result in the process
being killed, then kill -9
is sent after the kill_timeout
duration has elapsed.
Trait Implementations
impl Drop for PtyProcess
[src]
Auto Trait Implementations
impl RefUnwindSafe for PtyProcess
impl Send for PtyProcess
impl Sync for PtyProcess
impl Unpin for PtyProcess
impl UnwindSafe for PtyProcess
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>,
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<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,