From 72d04da8a9e9d369b0c24360bbd45b66f0f025d7 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 31 Mar 2025 20:10:19 +0200 Subject: [PATCH] init: Improve command spawning The stdout and stderr of the spawned processes are not captured by init, so attempting to write captured input is useless. Also show the exit code in case the child process returned an non-zero exit code. --- init/src/main.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/init/src/main.rs b/init/src/main.rs index 8b8eef158f..39186a44ec 100644 --- a/init/src/main.rs +++ b/init/src/main.rs @@ -2,7 +2,7 @@ use std::collections::BTreeMap; use std::env; use std::ffi::CString; use std::fs::{read_dir, File}; -use std::io::{BufRead, BufReader, Result, Write}; +use std::io::{BufRead, BufReader, Result}; use std::path::Path; use std::process::Command; @@ -186,15 +186,13 @@ pub fn run(file: &Path) -> Result<()> { } match command.spawn() { - Ok(child) => match child.wait_with_output() { - Ok(output) => { - std::io::stdout() - .write_all(output.stdout.as_slice()) - .unwrap(); - std::io::stderr() - .write_all(output.stderr.as_slice()) - .unwrap(); - println!("{cmd} done."); + Ok(mut child) => match child.wait() { + Ok(exit_status) => { + if !exit_status.success() { + println!("{cmd} failed with {exit_status}"); + } else { + println!("{cmd} done."); + } } Err(err) => { println!("init: failed to wait for '{}': {}", line, err)