ryna/algorithms/
shell.rs

1use std::{io::{BufRead, BufReader}, path::PathBuf};
2
3use subprocess::{Exec, Redirection};
4
5pub fn execute_command(command: &str, module_path: &PathBuf) -> bool {
6    let mut process = Exec::shell(command)
7        .cwd(module_path)
8        .stdout(Redirection::Pipe)
9        .stderr(Redirection::Merge)
10        .popen()
11        .expect("Failed to start process");
12
13    let stdout = process.stdout.take().expect("Failed to capture stdout");
14
15    let reader = BufReader::new(stdout);
16    
17    for line in reader.lines() {
18        match line {
19            Ok(l) => println!("{}", l),
20            Err(e) => eprintln!("Error reading line: {}", e),
21        }
22    }
23
24    return process.wait().expect("Process wasn't running").success();
25}