Skip to content

Commit

Permalink
command: Pass Ctrl+C on in Windows
Browse files Browse the repository at this point in the history
Attempt to replicate the functionality from
<rust-lang/cargo#6004>
in order to pass Ctrl+C on in Windows

Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
  • Loading branch information
kinnison committed Sep 25, 2019
1 parent 47faf31 commit 62f28d3
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ pub fn run_command_for_dir<S: AsRef<OsStr>>(

#[cfg(windows)]
fn exec(cmd: &mut Command) -> io::Result<ExitCode> {
use winapi::shared::minwindef::{BOOL, DWORD, FALSE, TRUE};
use winapi::um::consoleapi::SetConsoleCtrlHandler;

unsafe extern "system" fn ctrlc_handler(_: DWORD) -> BOOL {
// Do nothing. Let the child process handle it.
TRUE
}
unsafe {
if SetConsoleCtrlHandler(Some(ctrlc_handler), TRUE) == FALSE {
return Err(io::Error::new(
io::ErrorKind::Other,
"Unable to set console handler",
));
}
}
let status = cmd.status()?;
Ok(ExitCode(status.code().unwrap()))
}
Expand Down

0 comments on commit 62f28d3

Please sign in to comment.