From 3b7ee58cfaa5a7ab24e778a28eada0993ea489b9 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Thu, 6 Nov 2025 10:47:54 +0100 Subject: [PATCH] zed: Attach console to parent process before processing `--printenv` (#42075) Otherwise the `--printenv` flag will simply not work on windows Release Notes: - N/A *or* Added/Fixed/Improved ... --- crates/zed/src/main.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index 18903d888090bbc1fa0955d46417486a3f9fe13b..e3fb37b902667848b4054cfaed0d61705b7d2287 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -190,6 +190,15 @@ pub fn main() { } } + #[cfg(all(not(debug_assertions), target_os = "windows"))] + unsafe { + use windows::Win32::System::Console::{ATTACH_PARENT_PROCESS, AttachConsole}; + + if args.foreground { + let _ = AttachConsole(ATTACH_PARENT_PROCESS); + } + } + // `zed --printenv` Outputs environment variables as JSON to stdout if args.printenv { util::shell_env::print_env(); @@ -206,15 +215,6 @@ pub fn main() { paths::set_custom_data_dir(dir); } - #[cfg(all(not(debug_assertions), target_os = "windows"))] - unsafe { - use windows::Win32::System::Console::{ATTACH_PARENT_PROCESS, AttachConsole}; - - if args.foreground { - let _ = AttachConsole(ATTACH_PARENT_PROCESS); - } - } - #[cfg(target_os = "windows")] match util::get_zed_cli_path() { Ok(path) => askpass::set_askpass_program(path),