Struct sopht::process::Process

source ·
pub struct Process {
    pub prog: String,
    pub args: Vec<String>,
    pub child: Child,
    pub output: Vec<u8>,
    pub working_dir: PathBuf,
    /* private fields */
}
Expand description

contains all information about a running or previously-running process, including the Child structure and the handles to the threads reading the output streams of the process. this structure also maintains a Vec<String> containing all the output lines of its child process. for more info about how this output is read and stored, see Process::start

Fields§

§prog: String

the path of the process’ program

§args: Vec<String>

list of arguments to the process

§child: Child

handle to the child process. note: the stdin, stdout, and stderr are all None as they have been moved into this structure

§output: Vec<u8>

list of all lines of output collected by the receiver. this list can be populated by calling Process::gather_output, which will move lines from the receiver into this list

§working_dir: PathBuf

working directory of the process

Implementations§

source§

impl Process

source

pub fn start( prog: &String, args: &Vec<String>, working_dir: &Path ) -> Result<Self>

attempts to start and create a Process from a command string. this function can fail if:

this function also starts two threads to read the stdout and stderr of the child process without blocking the main thread. this is considered an acceptable overhead, since these reader threads create BufReaders internally and will spend most of their time sleeping and waiting for the OS to give them more data

source

pub fn gather_output(&mut self)

takes all output lines from the internal receiver and pushes them into the output array

source

pub fn is_alive(&mut self) -> Option<bool>

checks if the process is alive. this function returns an Option<bool> for completeness because it is technically possible for the status to be unknown (see the Win32 docs for WaitForSingleObject), though the return value of this function can probably be safely unwrapped most of the time since failure should be rare

source

pub fn exit_status(&mut self) -> Option<ExitStatus>

retrieves the exit status of the process. if the process has not exited or the status is unavailable, returns None

source

pub fn kill(&mut self) -> Result<()>

attempts to kill the process. returns a ProcessError on failure

source

pub fn send_input(&mut self, line: &str) -> Result<()>

attempts to send input to the process. this function can fail if the write implementation for ChildStdin fails, and in that case will return a ProcessError containing the internal error note: this function appends a newline to all strings!

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>,

§

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>,

§

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.