diff --git a/crates/uv-trampoline/Cargo.toml b/crates/uv-trampoline/Cargo.toml index 6a16fa8f9a7cd..8f0a705796639 100644 --- a/crates/uv-trampoline/Cargo.toml +++ b/crates/uv-trampoline/Cargo.toml @@ -47,6 +47,7 @@ windows = { version = "0.61.0", features = [ "Win32_System_LibraryLoader", "Win32_System_Threading", "Win32_UI_WindowsAndMessaging", + "Win32_Storage_FileSystem", ] } ufmt-write = "0.1.0" ufmt = { version = "0.2.0", features = ["std"] } diff --git a/crates/uv-trampoline/src/bounce.rs b/crates/uv-trampoline/src/bounce.rs index c1fb236eb4615..23ee6b8f032fa 100644 --- a/crates/uv-trampoline/src/bounce.rs +++ b/crates/uv-trampoline/src/bounce.rs @@ -8,6 +8,7 @@ use windows::Win32::{ Foundation::{ CloseHandle, HANDLE, HANDLE_FLAG_INHERIT, INVALID_HANDLE_VALUE, SetHandleInformation, TRUE, }, + Storage::FileSystem::{FILE_TYPE_PIPE, GetFileType}, System::Console::{ GetStdHandle, STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, SetConsoleCtrlHandler, SetStdHandle, }, @@ -345,6 +346,9 @@ fn close_handles(si: &STARTUPINFOA) { // Unlike cleanup_standard_io(), we don't close STD_ERROR_HANDLE to retain warn! for std_handle in [STD_INPUT_HANDLE, STD_OUTPUT_HANDLE] { if let Ok(handle) = unsafe { GetStdHandle(std_handle) } { + if handle.is_invalid() || unsafe { GetFileType(handle) } != FILE_TYPE_PIPE { + continue; + } unsafe { CloseHandle(handle) }.unwrap_or_else(|_| { warn!("Failed to close standard device handle {}", handle.0 as u32); });