Skip to main content

alwith_api/
process.rs

1//! Platform details for spawning child processes: no console window pops up on Windows spawn. The
2//! client spawning Runtime and modules spawning their own
3//! child processes both use it; it is a no-op on non-Windows, so call sites need no
4//! `#[cfg(windows)]`.
5
6#[cfg(windows)]
7const CREATE_NO_WINDOW: u32 = 0x0800_0000;
8
9pub trait HideConsoleExt {
10    fn hide_console(&mut self) -> &mut Self;
11}
12
13impl HideConsoleExt for std::process::Command {
14    fn hide_console(&mut self) -> &mut Self {
15        #[cfg(windows)]
16        {
17            use std::os::windows::process::CommandExt;
18            self.creation_flags(CREATE_NO_WINDOW);
19        }
20        self
21    }
22}
23
24impl HideConsoleExt for tokio::process::Command {
25    fn hide_console(&mut self) -> &mut Self {
26        #[cfg(windows)]
27        {
28            self.creation_flags(CREATE_NO_WINDOW);
29        }
30        self
31    }
32}