Trait std::os::windows::process::CommandExt

1.16.0 · source ·
pub trait CommandExt: Sealed {
    // Required methods
    fn creation_flags(&mut self, flags: u32) -> &mut Command;
    fn force_quotes(&mut self, enabled: bool) -> &mut Command;
    fn raw_arg<S: AsRef<OsStr>>(
        &mut self,
        text_to_append_as_is: S
    ) -> &mut Command;
    fn async_pipes(&mut self, always_async: bool) -> &mut Command;
}
Available on Windows only.
Expand description

Windows-specific extensions to the process::Command builder.

This trait is sealed: it cannot be implemented outside the standard library. This is so that future additional methods are not breaking changes.

Required Methods§

source

fn creation_flags(&mut self, flags: u32) -> &mut Command

Sets the process creation flags to be passed to CreateProcess.

These will always be ORed with CREATE_UNICODE_ENVIRONMENT.

source

fn force_quotes(&mut self, enabled: bool) -> &mut Command

🔬This is a nightly-only experimental API. (windows_process_extensions_force_quotes #82227)

Forces all arguments to be wrapped in quote (") characters.

This is useful for passing arguments to MSYS2/Cygwin based executables: these programs will expand unquoted arguments containing wildcard characters (? and *) by searching for any file paths matching the wildcard pattern.

Adding quotes has no effect when passing arguments to programs that use msvcrt. This includes programs built with both MinGW and MSVC.

1.62.0 · source

fn raw_arg<S: AsRef<OsStr>>(&mut self, text_to_append_as_is: S) -> &mut Command

Append literal text to the command line without any quoting or escaping.

This is useful for passing arguments to cmd.exe /c, which doesn’t follow CommandLineToArgvW escaping rules.

source

fn async_pipes(&mut self, always_async: bool) -> &mut Command

🔬This is a nightly-only experimental API. (windows_process_extensions_async_pipes #98289)

When process::Command creates pipes, request that our side is always async.

By default process::Command may choose to use pipes where both ends are opened for synchronous read or write operations. By using async_pipes(true), this behavior is overridden so that our side is always async.

This is important because if doing async I/O a pipe or a file has to be opened for async access.

The end of the pipe sent to the child process will always be synchronous regardless of this option.

Example
#![feature(windows_process_extensions_async_pipes)]
use std::os::windows::process::CommandExt;
use std::process::{Command, Stdio};


Command::new(program)
    .async_pipes(true)
    .stdin(Stdio::piped())
    .stdout(Stdio::piped())
    .stderr(Stdio::piped());
Run

Implementors§