pub const CREATE_NO_WINDOW: u32 = 0x0800_0000;
pub trait NoWindow {
fn no_window(&mut self) -> &mut Self;
}
impl NoWindow for std::process::Command {
fn no_window(&mut self) -> &mut Self {
#[cfg(windows)]
{
use std::os::windows::process::CommandExt;
self.creation_flags(CREATE_NO_WINDOW);
}
self
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn the_flag_value_is_the_windows_constant() {
assert_eq!(CREATE_NO_WINDOW, 0x0800_0000);
}
#[test]
fn a_std_command_chains_and_still_runs() {
let mut command = if cfg!(windows) {
let mut c = std::process::Command::new("cmd");
c.args(["/C", "exit 0"]);
c
} else {
std::process::Command::new("true")
};
let status = command.no_window().status().expect("run");
assert!(status.success());
}
}