Skip to content

Commit

Permalink
remove unnecessary stdout capture_log thread
Browse files Browse the repository at this point in the history
  • Loading branch information
weezy20 committed Dec 2, 2024
1 parent baebbb0 commit 0357fd4
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,12 @@ fn main() -> anyhow::Result<()> {
fn run_process(command: &str, args: &[&str], working_dir: &str, capture_log: bool) -> Child {
let mut cmd = Command::new(command);
if !capture_log {
let child = cmd
.args(args)
cmd.args(args)
.current_dir(working_dir)
.stdout(std::process::Stdio::null())
.stderr(std::process::Stdio::null())
.spawn()
.expect(&f!("Failed to start {:?}", command));
// Return handle to the spawned process
child
.expect(&f!("Failed to start {:?}", command))
} else {
let mut child = cmd
.args(args)
Expand All @@ -104,16 +101,9 @@ fn run_process(command: &str, args: &[&str], working_dir: &str, capture_log: boo
.spawn()
.expect(&f!("Failed to start {:?}", command));

let stdout = child.stdout.take().expect("Failed to open stdout");
// capture_log maybe used only for node-processes as such, it is sensible to only spawn a thread to print stderr
let stderr = child.stderr.take().expect("Failed to open stderr");

std::thread::spawn(move || {
let reader = std::io::BufReader::new(stdout);
for line in reader.lines() {
println!("stdout> {}", line.expect("Failed to read line from stdout"));
}
});

std::thread::spawn(move || {
let reader = std::io::BufReader::new(stderr);
for line in reader.lines() {
Expand Down

0 comments on commit 0357fd4

Please sign in to comment.