Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposing STARTUPINFOW.wShowWindow in CommandExt trait #126690

Merged
merged 3 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions library/std/src/os/windows/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ 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` 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>
#[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.
///
/// This is useful for passing arguments to [MSYS2/Cygwin][1] based
Expand Down Expand Up @@ -370,6 +378,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
Expand Down
10 changes: 10 additions & 0 deletions library/std/src/sys/pal/windows/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ pub struct Command {
env: CommandEnv,
cwd: Option<OsString>,
flags: u32,
show_window: Option<u16>,
detach: bool, // not currently exposed in std::process
stdin: Option<Stdio>,
stdout: Option<Stdio>,
Expand Down Expand Up @@ -194,6 +195,7 @@ impl Command {
env: Default::default(),
cwd: None,
flags: 0,
show_window: None,
detach: false,
stdin: None,
stdout: None,
Expand Down Expand Up @@ -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<u16>) {
self.show_window = cmd_show;
}

pub fn force_quotes(&mut self, enabled: bool) {
self.force_quotes_enabled = enabled;
Expand Down Expand Up @@ -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;
Expand Down
Loading