Skip to content

Commit c9fadb6

Browse files
authored
Merge pull request #52 from fornwall/use-exec-on-unix
Use exec() on unix
2 parents 7017fb0 + 445d9cf commit c9fadb6

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

src/main.rs

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ mod file_assoc;
1818
#[cfg(not(windows))]
1919
mod file_assoc {}
2020

21+
#[cfg(unix)]
22+
use std::os::unix::process::CommandExt;
23+
2124
use log::{debug, error, info};
2225
use serde::{Deserialize, Serialize};
2326
use std::ffi::OsString;
@@ -478,18 +481,34 @@ fn try_main() -> MainResult<i32> {
478481
})
479482
};
480483

481-
let exit_code = if action.execute {
482-
let cmd_name = action.build_kind.exec_command();
483-
info!("running `cargo {}`", cmd_name);
484-
let run_quietly = !action.cargo_output;
485-
let mut cmd = action.cargo(cmd_name, &args.script_args, run_quietly)?;
486-
487-
cmd.status().map(|st| st.code().unwrap_or(1))?
488-
} else {
489-
0
490-
};
484+
#[cfg(unix)]
485+
{
486+
if action.execute {
487+
let cmd_name = action.build_kind.exec_command();
488+
info!("running `cargo {}`", cmd_name);
489+
let run_quietly = !action.cargo_output;
490+
let mut cmd = action.cargo(cmd_name, &args.script_args, run_quietly)?;
491+
492+
let err = cmd.exec();
493+
Err(MainError::from(err))
494+
} else {
495+
Ok(0)
496+
}
497+
}
498+
#[cfg(not(unix))]
499+
{
500+
let exit_code = if action.execute {
501+
let cmd_name = action.build_kind.exec_command();
502+
info!("running `cargo {}`", cmd_name);
503+
let run_quietly = !action.cargo_output;
504+
let mut cmd = action.cargo(cmd_name, &args.script_args, run_quietly)?;
491505

492-
Ok(exit_code)
506+
cmd.status().map(|st| st.code().unwrap_or(1))?
507+
} else {
508+
0
509+
};
510+
Ok(exit_code)
511+
}
493512
}
494513

495514
/**

0 commit comments

Comments
 (0)