55 lines
1.0 KiB
Rust
55 lines
1.0 KiB
Rust
|
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<()> {
|
||
|
println!("executing shell action: {}", self.path.clone());
|
||
|
|
||
|
println!(
|
||
|
"
|
||
|
===
|
||
|
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() {
|
||
|
println!("{}", line);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
process.wait()?;
|
||
|
|
||
|
println!(
|
||
|
"
|
||
|
===
|
||
|
Finished running shell action
|
||
|
===
|
||
|
"
|
||
|
);
|
||
|
|
||
|
Ok(())
|
||
|
}
|
||
|
}
|