Skip to main content

ExecExt

Trait ExecExt 

Source
pub trait ExecExt {
    // Required methods
    fn creation_flags(self, flags: u32) -> Self;
    fn raw_arg(self, arg: impl Into<OsString>) -> Self;
}
Expand description

Extension trait for Windows-specific process creation options.

Required Methods§

Source

fn creation_flags(self, flags: u32) -> Self

Set process creation flags for Windows.

This value is passed to the dwCreationFlags parameter of CreateProcessW. Use this to control process creation behavior such as creating the process without a console window.

Source

fn raw_arg(self, arg: impl Into<OsString>) -> Self

Appends arg to the command line without quoting or escaping.

This is useful for passing arguments to programs that use non-standard command line parsing, such as cmd.exe /c. For example, passing git commit -m "feat: widget" through arg would apply MSVC-style argv quoting, producing backslash escapes that cmd.exe would interpret literally.

Exec::shell uses this method to pass the command string to cmd.exe /c.

§Background

On Windows, process arguments are not passed as an array (as on Unix) but as a single command-line string to CreateProcessW. The regular arg method applies MSVC C runtime quoting rules so that programs using standard CommandLineToArgvW parsing can reconstruct the original arguments. raw_arg bypasses all quoting and passes its argument to the command line verbatim. This is equivalent to raw_arg in the standard library.

Only use raw_arg with hardcoded or carefully validated input, as no quoting or escaping is applied. Exec::shell is an exception - a shell command must reach the shell verbatim, so quoting would corrupt it rather than protect it.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§