pub struct Process { /* private fields */ }Expand description
A program the shell runs, from cx.process(command). A clone is cheap
and shares it.
It starts on the loop’s next turn, so on_line and with_stdin set
right after cx.process apply to it. It runs in a process group of its
own, and that group gets SIGTERM when the context that started it
goes or the command starts again. Nothing polls: the shell wakes when
the program prints, takes input or ends.
Implementations§
Source§impl Process
impl Process
Sourcepub fn running(&self) -> ReadSignal<bool>
pub fn running(&self) -> ReadSignal<bool>
true from cx.process or a restart until the program ends or
can’t start.
Sourcepub fn exit_status(&self) -> ReadSignal<Option<ExitStatus>>
pub fn exit_status(&self) -> ReadSignal<Option<ExitStatus>>
How the last run ended: None while it runs, or if it couldn’t
start.
Sourcepub fn stdout(&self) -> ReadSignal<String>
pub fn stdout(&self) -> ReadSignal<String>
Everything it printed on its standard output this run, up to 1 MiB,
decoded as UTF-8 with bad bytes replaced. Complete once
exit_status is set.
Sourcepub fn stderr(&self) -> ReadSignal<String>
pub fn stderr(&self) -> ReadSignal<String>
Like stdout, for its standard error.
Sourcepub fn on_line(self, on_line: impl Fn(&str) + 'static) -> Process
pub fn on_line(self, on_line: impl Fn(&str) + 'static) -> Process
Calls on_line with each line of its standard output, without its
\n, decoded as UTF-8 with bad bytes replaced, as it comes. What is
left when it ends counts as a last line. A line over 1 MiB is
dropped and logged.
It runs on the main thread. If it panics, that is logged with the
program and where on_line was called, and it isn’t called again.
Sourcepub fn with_stdin(self) -> Process
pub fn with_stdin(self) -> Process
Gives the program an input that write feeds, open
until close_stdin. Without it the program’s
input is empty. It applies from the next start, so call it right
after cx.process.
Sourcepub fn write(&self, data: impl AsRef<[u8]>)
pub fn write(&self, data: impl AsRef<[u8]>)
Sends data to the program’s input, as it takes it; written before
the program started, it waits for the start. Without
with_stdin, or once the input is closed, data
is dropped and that is logged. If more than 4 MiB wait because the
program reads nothing, its input is closed.
Sourcepub fn close_stdin(&self)
pub fn close_stdin(&self)
Closes the program’s input once what was written is sent, so it reads the end of it.