From 445d9cfa3cabcb2ee9cf37102d3029380db51d31 Mon Sep 17 00:00:00 2001 From: Fredrik Fornwall Date: Wed, 27 Apr 2022 11:55:59 +0200 Subject: [PATCH] Use exec() on unix See #24. --- src/main.rs | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index c8f5c7e..c143a59 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,6 +18,9 @@ mod file_assoc; #[cfg(not(windows))] mod file_assoc {} +#[cfg(unix)] +use std::os::unix::process::CommandExt; + use log::{debug, error, info}; use serde::{Deserialize, Serialize}; use std::ffi::OsString; @@ -478,18 +481,34 @@ fn try_main() -> MainResult { }) }; - let exit_code = if action.execute { - let cmd_name = action.build_kind.exec_command(); - info!("running `cargo {}`", cmd_name); - let run_quietly = !action.cargo_output; - let mut cmd = action.cargo(cmd_name, &args.script_args, run_quietly)?; - - cmd.status().map(|st| st.code().unwrap_or(1))? - } else { - 0 - }; + #[cfg(unix)] + { + if action.execute { + let cmd_name = action.build_kind.exec_command(); + info!("running `cargo {}`", cmd_name); + let run_quietly = !action.cargo_output; + let mut cmd = action.cargo(cmd_name, &args.script_args, run_quietly)?; + + let err = cmd.exec(); + Err(MainError::from(err)) + } else { + Ok(0) + } + } + #[cfg(not(unix))] + { + let exit_code = if action.execute { + let cmd_name = action.build_kind.exec_command(); + info!("running `cargo {}`", cmd_name); + let run_quietly = !action.cargo_output; + let mut cmd = action.cargo(cmd_name, &args.script_args, run_quietly)?; - Ok(exit_code) + cmd.status().map(|st| st.code().unwrap_or(1))? + } else { + 0 + }; + Ok(exit_code) + } } /**