cargo_newcpp/
command_helper.rs

1use std::process::{Command, Stdio};
2use std::io::{BufRead, BufReader};
3
4pub fn dump_command(cmd: &mut Command){
5    cmd.stdout(Stdio::piped());  
6    let mut child = cmd.spawn().unwrap();  
7    let stdout = child.stdout.take().expect("Failed to get stdout");
8
9    // Create a buffer reader to read the output line by line
10    let reader = BufReader::new(stdout);
11
12    // Read and print the output in real-time
13    for line in reader.lines() {
14        match line {
15            Ok(line) => println!("{}", line),
16            Err(e) => eprintln!("Error reading line: {}", e),
17        }
18    }    
19
20    // Wait for the command to finish and check if it was successful
21    let status = child.wait().unwrap();
22    if !status.success() {
23        println!("Command failed with exit code: {:?}", status.code());
24    }
25}
26
27pub fn run_command(cmd: &mut Command){
28
29    cmd.stdout(Stdio::piped());  
30    cmd.stderr(Stdio::piped());  
31    let mut child = cmd.spawn().unwrap();  
32    // let stdout = child.stdout.take().expect("Failed to get stdout");
33    // let sterr = child.stderr.take().expect("Failed to get stderr");
34
35    // Wait for the command to finish and check if it was successful
36    let status = child.wait().unwrap();
37    if !status.success() {
38        println!("Command failed with exit code: {:?}", status.code());
39    }
40}
41
42/*
43    Ok(_) => println!("Was spawned :)"),
44    Err(e) => {
45        if let NotFound = e.kind() {
46            println!("`rustc` was not found! Check your PATH!")
47        } else {
48            println!("Some strange error occurred :(");
49        }
50    }, 
51*/