Skip to main content

PTYProcess

Struct PTYProcess 

Source
pub struct PTYProcess { /* private fields */ }
Expand description

This struct handles the I/O operations to the standard streams, as well the lifetime of a process running inside a PTY.

Implementations§

Source§

impl PTYProcess

Source

pub fn new( conin: LocalHandle, conout: LocalHandle, using_pipes: bool, async_: bool, cleanup_tx: Option<Sender<bool>>, ) -> PTYProcess

Create a new PTYProcess instance.

§Arguments
  • conin - Handle to the process standard input stream
  • conout - Handle to the process standard output stream
  • using_pipes - true if the streams are Windows named pipes, false if they are files.
  • async_ - true if the streams are async, false if they are sync.
§Returns
Source

pub fn read(&self, blocking: bool) -> Result<OsString, OsString>

Read from the process standard output.

§Arguments
  • blocking - If true, wait for data to be available. If false, return immediately if no data is available.
§Returns
  • Ok(OsString) - The data read from the process output
  • Err(OsString) - If EOF is reached or an error occurs
§Notes
  • The actual read operation happens in a background thread with a fixed buffer size
  • The returned data is represented using a OsString since Windows operates over u16 strings
Source

pub fn write(&self, buf: OsString) -> Result<u32, OsString>

Write an (possibly) UTF-16 string into the standard input of a process.

§Arguments
  • buf - OsString containing the string to write.
§Returns

The total number of characters written if the call was successful, else an OsString containing an human-readable error.

Source

pub fn is_eof(&self) -> Result<bool, OsString>

Check if a process reached End-of-File (EOF).

§Returns

true if the process reached EOL, false otherwise. If an error occurs, then a OsString containing a human-readable error is raised.

Source

pub fn get_exitstatus(&self) -> Result<Option<u32>, OsString>

Retrieve the exit status of the process

§Returns

None if the process has not exited, else the exit code of the process.

Source

pub fn is_alive(&self) -> Result<bool, OsString>

Determine if the process is still alive.

Source

pub fn set_process(&mut self, process: HANDLE, close_process: bool)

Set the running process behind the PTY.

Source

pub fn get_pid(&self) -> u32

Retrieve the Process ID associated to the current process.

Source

pub fn get_fd(&self) -> isize

Retrieve the process handle ID of the spawned program.

Source

pub fn wait_for_exit(&self) -> Result<bool, OsString>

Wait for the process to exit

Source

pub fn cancel_io(&self) -> Result<bool, OsString>

Cancel all pending I/O operations

Trait Implementations§

Source§

impl Drop for PTYProcess

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.