use std::ffi::OsStr;
use std::process::Command;
pub(crate) fn hidden_command(program: impl AsRef<OsStr>) -> Command {
#[allow(unused_mut)]
let mut command = Command::new(program);
#[cfg(windows)]
{
use std::os::windows::process::CommandExt;
const CREATE_NO_WINDOW: u32 = 0x0800_0000;
command.creation_flags(CREATE_NO_WINDOW);
}
command
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_hidden_command_runs_and_captures_output() {
#[cfg(windows)]
let output = hidden_command("cmd")
.args(["/C", "echo hidden-ok"])
.output()
.expect("hidden_command should spawn");
#[cfg(not(windows))]
let output = hidden_command("sh")
.args(["-c", "echo hidden-ok"])
.output()
.expect("hidden_command should spawn");
assert!(output.status.success());
assert!(String::from_utf8_lossy(&output.stdout).contains("hidden-ok"));
}
}