pub struct Process { /* private fields */ }Expand description
A process Launcher::spawn started, the leader of a process group of
its own. Dropping it while it runs kills the group and reaps it.
Implementations§
Source§impl Process
impl Process
Sourcepub fn through(self, host: impl Into<String>) -> Self
pub fn through(self, host: impl Into<String>) -> Self
The same process, marked as the local end of a transport that runs
the command on the machine host: stopping it stops the transport,
and what that does there is the transport’s to say.
Sourcepub fn remote(&self) -> Option<&str>
pub fn remote(&self) -> Option<&str>
The machine it runs the command on through a transport, if it was
marked so (through).
Sourcepub fn forced(&self) -> bool
pub fn forced(&self) -> bool
Whether the last stop had to kill it: it was still
running its grace period after SIGTERM.
Sourcepub fn lines(&self) -> &Receiver<OutputLine>
pub fn lines(&self) -> &Receiver<OutputLine>
Its output, line by line, as it comes. Lines wait here until they are received; the channel disconnects once every process holding the output closed it.
Sourcepub fn group(&self) -> Group
pub fn group(&self) -> Group
A handle that stops its group from another thread, such as the one dropping the call that waits for it.
Sourcepub fn try_wait(&mut self) -> Result<Option<ExitStatus>>
pub fn try_wait(&mut self) -> Result<Option<ExitStatus>>
How it ended, if it has.
Sourcepub fn wait_for(&mut self, timeout: Duration) -> Result<Option<ExitStatus>>
pub fn wait_for(&mut self, timeout: Duration) -> Result<Option<ExitStatus>>
Waits at most timeout for it to end, and says how it ended if it
did. Its output keeps arriving at lines meanwhile.
A timeout too long for the clock, such as Duration::MAX, waits
until it ends.
Sourcepub fn output(self, timeout: Option<Duration>) -> Result<Output>
pub fn output(self, timeout: Option<Duration>) -> Result<Output>
Runs it to its end, at most timeout (None waits as long as it
takes), and returns what it printed on stdout and on stderr (with
Spawn::merge_stderr, all of it on stdout) and how it ended. A
blocking call: run it on a thread of its own, such as inside
blocking. Past timeout the error is
io::ErrorKind::TimedOut; otherwise as run.
use rig_tools::process::{Launcher, Spawn};
let process = Launcher::default().spawn("sh", ["-c", "echo hi"], Spawn::default())?;
let output = process.output(Some(std::time::Duration::from_secs(5)))?;
assert_eq!(output.stdout, b"hi\n");
assert!(output.status.success());Sourcepub fn run(
&mut self,
deadline: Option<Instant>,
quiet: Option<Duration>,
sink: impl FnMut(OutputLine) -> bool,
) -> Result<Ended>
pub fn run( &mut self, deadline: Option<Instant>, quiet: Option<Duration>, sink: impl FnMut(OutputLine) -> bool, ) -> Result<Ended>
Waits for it to end, at most until deadline (None waits as long
as it takes) and, with quiet, while it printed something within
that long, handing each piece of its output to sink; sink
returning false stops the wait. A blocking call.
After an exit, something it left running that still holds its
output gets a moment (100 ms) to finish, then the rest of its group
is killed; past the deadline or stopped, the group is
stopped with STOP_GRACE. After a kill, reading
goes on for that moment: a process that left the group survives the
kill and may hold the pipe for good.
Sourcepub fn stop(&mut self, grace: Duration) -> Result<ExitStatus>
pub fn stop(&mut self, grace: Duration) -> Result<ExitStatus>
Asks its group to stop (SIGTERM), waits at most grace for it to
end, then kills the group. Elsewhere than unix it is
killed at once.
Sourcepub fn kill(&mut self) -> Result<ExitStatus>
pub fn kill(&mut self) -> Result<ExitStatus>
Kills its group (SIGKILL), also what is left of it after the
process itself ended, and says how the process ended. Kill within
moments of the end: once the group is empty its id is free again.