process_wrap/std/creation_flags.rs
1use std::{io::Result, os::windows::process::CommandExt, process::Command};
2
3use windows::Win32::System::Threading::PROCESS_CREATION_FLAGS;
4
5use super::{CommandWrap, CommandWrapper};
6
7/// Shim wrapper which sets Windows process creation flags.
8///
9/// This wrapper is only available on Windows.
10///
11/// It exists to be able to set creation flags on a `Command` and also store them in the wrapper, so
12/// that they're no overwritten by other wrappers. Notably this is the only way to use creation
13/// flags and the `JobObject` wrapper together.
14///
15/// When both `CreationFlags` and `JobObject` are used together, either:
16/// - `CreationFlags` must come first, or
17/// - `CreationFlags` must include `CREATE_SUSPENDED`
18#[derive(Clone, Copy, Debug)]
19pub struct CreationFlags(pub PROCESS_CREATION_FLAGS);
20
21impl CommandWrapper for CreationFlags {
22 fn pre_spawn(&mut self, command: &mut Command, _core: &CommandWrap) -> Result<()> {
23 command.creation_flags((self.0).0);
24 Ok(())
25 }
26}