pub struct Runner { /* private fields */ }Expand description
High-level async process runner with event-driven output handling.
Implementations§
Source§impl Runner
impl Runner
Sourcepub fn new(command: impl Into<String>, args: Vec<impl Into<String>>) -> Self
pub fn new(command: impl Into<String>, args: Vec<impl Into<String>>) -> Self
Create a new runner with command and arguments.
§Examples
use ej_io::runner::Runner;
let runner = Runner::new("ls", vec!["-la", "/tmp"]);Sourcepub fn new_without_args(command: impl Into<String>) -> Self
pub fn new_without_args(command: impl Into<String>) -> Self
Create a new runner with just a command (no arguments).
§Examples
use ej_io::runner::Runner;
let runner = Runner::new_without_args("pwd");Sourcepub fn get_full_command(&self) -> String
pub fn get_full_command(&self) -> String
Get the full command string with arguments.
§Examples
use ej_io::runner::Runner;
let runner = Runner::new("ls", vec!["-la"]);
assert_eq!(runner.get_full_command(), "ls -la");Sourcepub async fn run(
&self,
tx: Sender<RunEvent>,
should_stop: Arc<AtomicBool>,
) -> Option<ExitStatus>
pub async fn run( &self, tx: Sender<RunEvent>, should_stop: Arc<AtomicBool>, ) -> Option<ExitStatus>
Asynchronously run the process with event monitoring.
Starts the process and monitors its execution asynchronously, sending events via the provided tokio channel. Reads stdout and stderr concurrently until the process finishes or is stopped.
§Arguments
tx- Tokio async channel sender for RunEvent notificationsshould_stop- Atomic flag to signal process termination
§Returns
Returns an Option<ExitStatus> - None if the process failed to start or was terminated,
Some(ExitStatus) if the process completed normally.
§Examples
use ej_io::runner::{Runner, RunEvent};
use std::sync::{Arc, atomic::AtomicBool};
use tokio::sync::mpsc;
#[tokio::main]
async fn main() {
let runner = Runner::new("echo", vec!["Hello"]);
let (tx, mut rx) = mpsc::channel(100);
let should_stop = Arc::new(AtomicBool::new(false));
let exit_status = runner.run(tx, should_stop).await;
}Auto Trait Implementations§
impl Freeze for Runner
impl RefUnwindSafe for Runner
impl Send for Runner
impl Sync for Runner
impl Unpin for Runner
impl UnsafeUnpin for Runner
impl UnwindSafe for Runner
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more