cargo_newcpp/
command_helper.rs1use 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 let reader = BufReader::new(stdout);
11
12 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 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 status = child.wait().unwrap();
37 if !status.success() {
38 println!("Command failed with exit code: {:?}", status.code());
39 }
40}
41
42