use std::{ io::{BufRead, BufReader}, process::{Command, Stdio}, }; pub struct ShellAction { path: String, } impl ShellAction { pub fn new(path: String) -> Self { Self { path } } pub fn execute(self) -> anyhow::Result<()> { log::debug!("executing shell action: {}", self.path.clone()); log::info!( " === Starting running shell action: {} === ", self.path.clone() ); let mut process = Command::new(self.path) .current_dir(".") .stdout(Stdio::piped()) .stderr(Stdio::piped()) .spawn()?; { let stdout = process.stdout.as_mut().unwrap(); let stdout_reader = BufReader::new(stdout); let mut stdout_lines = stdout_reader.lines(); while let Some(Ok(line)) = stdout_lines.next() { log::info!("{}", line) } } process.wait()?; log::info!( " === Finished running shell action === " ); Ok(()) } }