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