1use colored::Colorize;
2use std::io::{BufRead, BufReader};
3use std::process;
4
5pub fn stream_output(mut child: process::Child) -> process::ExitCode {
20 let stdout = child.stdout.take().expect("Failed to capture stdout");
21 let stdout_reader = BufReader::new(stdout);
22 let stdout_lines = stdout_reader.lines();
23 let stderr = child.stderr.take().expect("Failed to capture stderr");
24 let stderr_reader = BufReader::new(stderr);
25 let stderr_lines = stderr_reader.lines();
26 let stdout_handle = std::thread::spawn(move || {
27 for line in stdout_lines {
28 if let Ok(line) = line {
29 println!("{}", line);
30 }
31 }
32 });
33 let stderr_handle = std::thread::spawn(move || {
34 for line in stderr_lines {
35 if let Ok(line) = line {
36 eprintln!("{}", line.red());
37 }
38 }
39 });
40 stdout_handle.join().unwrap();
41 stderr_handle.join().unwrap();
42 match child.wait() {
43 Ok(status) => {
44 if status.success() {
45 process::ExitCode::SUCCESS
46 } else {
47 process::ExitCode::FAILURE
48 }
49 }
50 Err(e) => {
51 eprintln!("Failed to wait for Python process: {}", e);
52 process::ExitCode::FAILURE
53 }
54 }
55}