use std::ffi::OsStr;
use std::process::Command;
#[cfg(windows)]
pub fn system32(relative: &str) -> String {
let root = std::env::var("SystemRoot").unwrap_or_else(|_| String::from(r"C:\Windows"));
format!("{root}\\System32\\{relative}")
}
pub fn command<S: AsRef<OsStr>>(program: S) -> Command {
let mut cmd = Command::new(program);
apply_window_policy(&mut cmd);
cmd
}
#[cfg(windows)]
fn apply_window_policy(cmd: &mut Command) {
use std::os::windows::process::CommandExt;
use std::sync::OnceLock;
const CREATE_NO_WINDOW: u32 = 0x0800_0000;
static HAS_CONSOLE: OnceLock<bool> = OnceLock::new();
let has_console = *HAS_CONSOLE.get_or_init(|| {
!unsafe { windows_sys::Win32::System::Console::GetConsoleWindow() }.is_null()
});
if !has_console {
cmd.creation_flags(CREATE_NO_WINDOW);
}
}
#[cfg(not(windows))]
fn apply_window_policy(_cmd: &mut Command) {}