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
impl Process
sourcepub fn start(
prog: &String,
args: &Vec<String>,
working_dir: &Path
) -> Result<Self>
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:
- the process fails to start (
ProcessError
) - the supplied command string is empty
(
EmptyProgram
)
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
BufReader
s internally and will spend most of their time sleeping and
waiting for the OS to give them more data
sourcepub fn gather_output(&mut self)
pub fn gather_output(&mut self)
takes all output lines from the internal receiver and pushes them into
the output
array
sourcepub fn is_alive(&mut self) -> Option<bool>
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
sourcepub fn exit_status(&mut self) -> Option<ExitStatus>
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
sourcepub fn kill(&mut self) -> Result<()>
pub fn kill(&mut self) -> Result<()>
attempts to kill the process. returns a
ProcessError
on failure
sourcepub fn send_input(&mut self, line: &str) -> Result<()>
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!