2023-07-17 20:40:22 +02:00
|
|
|
// create functions that spawn threads for Stdout and Stderr
|
|
|
|
// that print the output to info!(target: "command:stdout", ...) and info!(target: "command:stderr", ...) respectively
|
|
|
|
|
|
|
|
use std::io::{BufRead, BufReader};
|
2023-07-17 21:23:59 +02:00
|
|
|
use std::process::Child;
|
2023-07-17 20:40:22 +02:00
|
|
|
|
2023-07-17 21:23:59 +02:00
|
|
|
use log::{error, info};
|
2023-07-17 20:40:22 +02:00
|
|
|
|
|
|
|
pub fn spawn_output_handlers(child: &mut Child) {
|
|
|
|
let stdout = child.stdout.take().unwrap();
|
|
|
|
let stderr = child.stderr.take().unwrap();
|
|
|
|
|
|
|
|
std::thread::spawn(move || {
|
|
|
|
let reader = BufReader::new(stdout);
|
|
|
|
for line in reader.lines() {
|
|
|
|
info!(target: "command:stdout", "{}", line.unwrap());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
std::thread::spawn(move || {
|
|
|
|
let reader = BufReader::new(stderr);
|
|
|
|
for line in reader.lines() {
|
|
|
|
error!(target: "command:stderr", "{}", line.unwrap());
|
|
|
|
}
|
|
|
|
});
|
2023-07-17 21:23:59 +02:00
|
|
|
}
|