cranpose_services/helper_process.rs
1use std::{ffi::OsStr, process::Command};
2
3/// A [`Command`] for a helper program an application runs behind its window,
4/// such as `reg`, `powershell` or `notify-send`.
5///
6/// On Windows the program starts with no console window of its own. A desktop
7/// application built as a GUI program has no console to lend, so any console
8/// program it starts otherwise opens a terminal window that flashes and
9/// closes. Everywhere else this is `Command::new(program)`.
10pub fn windowless_command(program: impl AsRef<OsStr>) -> Command {
11 let command = Command::new(program);
12 #[cfg(windows)]
13 let command = {
14 use std::os::windows::process::CommandExt;
15
16 const CREATE_NO_WINDOW: u32 = 0x0800_0000;
17 let mut command = command;
18 command.creation_flags(CREATE_NO_WINDOW);
19 command
20 };
21 command
22}