packager/pkgr/src/process/output.rs
Didier b83d44768d
All checks were successful
/ check (push) Successful in 38s
feat: Process with multithreaded log pipes
2023-07-17 20:40:22 +02:00

26 lines
No EOL
813 B
Rust

// 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::process::Child;
use std::io::{BufRead, BufReader};
use log::{info, error};
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());
}
});
}