#[non_exhaustive]pub struct Job {
pub stdin: Option<File>,
pub stdout: Option<File>,
pub stderr: Option<File>,
pub stdin_data: InputData,
pub check_success: bool,
pub processes: Vec<Process>,
}Expand description
Interface to a started process or pipeline.
Created by [Exec::start] or [Pipeline::start].
When dropped, waits for all processes to finish unless detached.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.stdin: Option<File>Write end of the first process’s stdin pipe, if stdin was Pipe.
stdout: Option<File>Read end of the last process’s stdout pipe, if stdout was Pipe.
stderr: Option<File>Read end of the shared stderr pipe, if stderr was Pipe.
stdin_data: InputDataData to feed to the first process’s stdin, set by [Exec::stdin]
or [Pipeline::stdin].
check_success: boolWhether to return an error on non-zero exit status.
processes: Vec<Process>Started processes, in pipeline order.
Implementations§
Source§impl Job
impl Job
Sourcepub fn communicate(&mut self) -> Result<Communicator>
pub fn communicate(&mut self) -> Result<Communicator>
Creates a Communicator from the pipe ends.
The communicator takes ownership of stdin, stdout, and stderr, leaving them
as None. Only streams that were redirected to a pipe will be available to the
communicator.
Sourcepub fn terminate(&self) -> Result<()>
pub fn terminate(&self) -> Result<()>
Terminates all processes in the pipeline.
Delegates to Process::terminate() on each process, which sends SIGTERM on
Unix and calls TerminateProcess on Windows. Already reaped processes are
silently skipped.
Sourcepub fn wait(&self) -> Result<ExitStatus>
pub fn wait(&self) -> Result<ExitStatus>
Waits for all processes to finish and returns the last process’s exit status.
If no processes have been started (empty pipeline), returns a successful exit status.
Unlike join, this does not consume self, does not close the pipe
ends, and ignores check_success.
Sourcepub fn pid(&self) -> u32
pub fn pid(&self) -> u32
Returns the PID of the last process in the pipeline.
For a single command started with [Exec::start], this is the PID of that
command. For a pipeline, this is the PID of the last command.
§Panics
Panics if no processes have been started because this was created by an empty
Pipeline.
Sourcepub fn pids(&self) -> Vec<u32>
pub fn pids(&self) -> Vec<u32>
Returns the PIDs of all processes in the pipeline, in pipeline order.
If the job was started by a single process, this will return its pid. It will be empty for a job started by an empty pipeline.
Sourcepub fn kill(&self) -> Result<()>
pub fn kill(&self) -> Result<()>
Kill all processes in the pipeline.
Delegates to Process::kill() on each process, which sends SIGKILL on Unix
and calls TerminateProcess on Windows. Already reaped processes are silently
skipped.
Sourcepub fn detach(&self)
pub fn detach(&self)
Detach all processes in the pipeline.
After detaching, the processes will not be waited for in drop.
Sourcepub fn poll(&self) -> Option<ExitStatus>
pub fn poll(&self) -> Option<ExitStatus>
Poll all processes for completion without blocking.
Returns Some(exit_status) of the last process if all processes have finished, or
None if any process is still running. If no processes have been started (empty
pipeline), returns Some with a successful exit status.
Sourcepub fn wait_timeout(&self, timeout: Duration) -> Result<Option<ExitStatus>>
pub fn wait_timeout(&self, timeout: Duration) -> Result<Option<ExitStatus>>
Like wait, but with a timeout.
Returns Ok(None) if the processes don’t finish within the given duration.
Sourcepub fn join(self) -> Result<ExitStatus>
pub fn join(self) -> Result<ExitStatus>
Closes the pipe ends, waits for all processes to finish, and returns the exit status of the last process.
If input or output was redirected to pipe, this close input and drain the output as needed.
Sourcepub fn join_timeout(self, timeout: Duration) -> Result<ExitStatus>
pub fn join_timeout(self, timeout: Duration) -> Result<ExitStatus>
Like join, but with a timeout.
Returns an error of kind ErrorKind::TimedOut if the processes don’t finish
within the given duration.