From 06d76c3156a8245067473fcc62bc5669f468bf4f Mon Sep 17 00:00:00 2001 From: Andres Olivares Date: Wed, 19 Jun 2024 10:15:50 -0400 Subject: [PATCH 1/3] Exposing STARTUPINFOW.wShowWindow in CommandExt (show_window function) to control how a new process should display its window (normal, minimized, maximized, etc) --- library/std/src/os/windows/process.rs | 12 ++++++++++++ library/std/src/sys/pal/windows/process.rs | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/library/std/src/os/windows/process.rs b/library/std/src/os/windows/process.rs index 9cca27fa5dd5b..b5afdf9868f25 100644 --- a/library/std/src/os/windows/process.rs +++ b/library/std/src/os/windows/process.rs @@ -181,6 +181,13 @@ pub trait CommandExt: Sealed { #[stable(feature = "windows_process_extensions", since = "1.16.0")] fn creation_flags(&mut self, flags: u32) -> &mut process::Command; + /// Sets the field [wShowWindow][1] of [STARTUPINFO][2] that is passed to `CreateProcess`. + /// + /// [1]: https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow + /// [2]: https://learn.microsoft.com/es-es/windows/win32/api/processthreadsapi/ns-processthreadsapi-startupinfow + #[unstable(feature = "windows_process_extensions_show_window", issue = "none")] + fn show_window(&mut self, cmd_show: u16) -> &mut process::Command; + /// Forces all arguments to be wrapped in quote (`"`) characters. /// /// This is useful for passing arguments to [MSYS2/Cygwin][1] based @@ -370,6 +377,11 @@ impl CommandExt for process::Command { self } + fn show_window(&mut self, cmd_show: u16) -> &mut process::Command { + self.as_inner_mut().show_window(Some(cmd_show)); + self + } + fn force_quotes(&mut self, enabled: bool) -> &mut process::Command { self.as_inner_mut().force_quotes(enabled); self diff --git a/library/std/src/sys/pal/windows/process.rs b/library/std/src/sys/pal/windows/process.rs index 2da986a1494ef..c62764696b86b 100644 --- a/library/std/src/sys/pal/windows/process.rs +++ b/library/std/src/sys/pal/windows/process.rs @@ -163,6 +163,7 @@ pub struct Command { env: CommandEnv, cwd: Option, flags: u32, + show_window: Option, detach: bool, // not currently exposed in std::process stdin: Option, stdout: Option, @@ -194,6 +195,7 @@ impl Command { env: Default::default(), cwd: None, flags: 0, + show_window: None, detach: false, stdin: None, stdout: None, @@ -224,6 +226,9 @@ impl Command { pub fn creation_flags(&mut self, flags: u32) { self.flags = flags; } + pub fn show_window(&mut self, cmd_show: Option) { + self.show_window = cmd_show; + } pub fn force_quotes(&mut self, enabled: bool) { self.force_quotes_enabled = enabled; @@ -337,6 +342,11 @@ impl Command { si.hStdError = stderr.as_raw_handle(); } + if let Some(cmd_show) = self.show_window { + si.dwFlags |= c::STARTF_USESHOWWINDOW; + si.wShowWindow = cmd_show; + } + let si_ptr: *mut c::STARTUPINFOW; let mut proc_thread_attribute_list; From e82ad2e62224c66ef0b6c9e11a79e73cf645f1b4 Mon Sep 17 00:00:00 2001 From: Andres Olivares Date: Tue, 9 Jul 2024 20:48:17 -0400 Subject: [PATCH 2/3] Few changes to doc comments. Added tracking issue number. --- library/std/src/os/windows/process.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/library/std/src/os/windows/process.rs b/library/std/src/os/windows/process.rs index b5afdf9868f25..a087fb4883014 100644 --- a/library/std/src/os/windows/process.rs +++ b/library/std/src/os/windows/process.rs @@ -181,11 +181,12 @@ pub trait CommandExt: Sealed { #[stable(feature = "windows_process_extensions", since = "1.16.0")] fn creation_flags(&mut self, flags: u32) -> &mut process::Command; - /// Sets the field [wShowWindow][1] of [STARTUPINFO][2] that is passed to `CreateProcess`. + /// Sets the field `wShowWindow` of [STARTUPINFO][1] that is passed to `CreateProcess`. + /// Allowed values are the ones listed in + /// https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow /// - /// [1]: https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow - /// [2]: https://learn.microsoft.com/es-es/windows/win32/api/processthreadsapi/ns-processthreadsapi-startupinfow - #[unstable(feature = "windows_process_extensions_show_window", issue = "none")] + /// [1]: https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/ns-processthreadsapi-startupinfow + #[unstable(feature = "windows_process_extensions_show_window", issue = "127544")] fn show_window(&mut self, cmd_show: u16) -> &mut process::Command; /// Forces all arguments to be wrapped in quote (`"`) characters. From b8b6d14de92986e420e782d9a587960f6792c7c2 Mon Sep 17 00:00:00 2001 From: Andres Olivares Date: Tue, 9 Jul 2024 21:46:20 -0400 Subject: [PATCH 3/3] Fixed doc links --- library/std/src/os/windows/process.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/std/src/os/windows/process.rs b/library/std/src/os/windows/process.rs index a087fb4883014..05ffb8925a1f0 100644 --- a/library/std/src/os/windows/process.rs +++ b/library/std/src/os/windows/process.rs @@ -183,9 +183,9 @@ pub trait CommandExt: Sealed { /// Sets the field `wShowWindow` of [STARTUPINFO][1] that is passed to `CreateProcess`. /// Allowed values are the ones listed in - /// https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow + /// /// - /// [1]: https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/ns-processthreadsapi-startupinfow + /// [1]: #[unstable(feature = "windows_process_extensions_show_window", issue = "127544")] fn show_window(&mut self, cmd_show: u16) -> &mut process::Command;