// 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()); } }); }