Calling GetStdHandle and then calling ctrl-c triggers error rather than clean exit #18699

Open
opened 2026-01-31 06:21:44 +00:00 by claunia · 0 comments
Owner

Originally created by @robinbernon on GitHub (Oct 16, 2022).

Windows Terminal version

1.15.2874.0

Windows build number

10.0.19044.0

Other Software

No response

Steps to reproduce

Create a rust project with the following code in main.rs (I guess the equivalent in C++ might also give the same output):

`use std::{thread, time::Duration};
use winapi::um::processenv::GetStdHandle;
use winapi::um::winbase::STD_OUTPUT_HANDLE;

fn main() {
let handle = unsafe {GetStdHandle(STD_OUTPUT_HANDLE)};

thread::sleep(Duration::from_secs(5));

}`

And then call cargo run. Before the program exits naturally after the 5 second sleep call ctr-c to manually terminate the program early.

Expected Behavior

Program should exit gracefully without error

Actual Behavior

Rather than failing gracefully the program fails with:

error: process didn't exit successfully: target\debug\your_program.exe (exit code: 0xc000013a, STATUS_CONTROL_C_EXIT)

Dropping or closing the handle also has no effect and the resulting error is the same.

Originally created by @robinbernon on GitHub (Oct 16, 2022). ### Windows Terminal version 1.15.2874.0 ### Windows build number 10.0.19044.0 ### Other Software _No response_ ### Steps to reproduce Create a rust project with the following code in main.rs (I guess the equivalent in C++ might also give the same output): `use std::{thread, time::Duration}; use winapi::um::processenv::GetStdHandle; use winapi::um::winbase::STD_OUTPUT_HANDLE; fn main() { let handle = unsafe {GetStdHandle(STD_OUTPUT_HANDLE)}; thread::sleep(Duration::from_secs(5)); }` And then call `cargo run`. Before the program exits naturally after the 5 second sleep call ctr-c to manually terminate the program early. ### Expected Behavior Program should exit gracefully without error ### Actual Behavior Rather than failing gracefully the program fails with: `error: process didn't exit successfully: `target\debug\your_program.exe` (exit code: 0xc000013a, STATUS_CONTROL_C_EXIT)` Dropping or closing the handle also has no effect and the resulting error is the same.
claunia added the Needs-TriageIssue-Bug labels 2026-01-31 06:21:44 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#18699