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 的 process::Command 构建器扩展。
这个 trait 是封闭的:它不能在标准库之外实现。 这是为了将来的附加方法不会破坏更改。
Required Methods§
sourcefn creation_flags(&mut self, flags: u32) -> &mut Command
 
fn creation_flags(&mut self, flags: u32) -> &mut Command
设置要传递给 CreateProcess 的 进程创建标志。
这些将始终与 CREATE_UNICODE_ENVIRONMENT 进行或运算。
sourcefn force_quotes(&mut self, enabled: bool) -> &mut Command
 
fn force_quotes(&mut self, enabled: bool) -> &mut Command
🔬This is a nightly-only experimental API. (
windows_process_extensions_force_quotes #82227)强制所有参数用 (") 引号括起来。
这对于将参数传递给基于 MSYS2/Cygwin 的可执行文件很有用:这些程序将通过搜索与通配符模式匹配的任何文件路径来扩展包含通配符 (? 和 *) 的不带引号的参数。
将参数传递给使用 msvcrt 的程序时,添加引号无效。这包括使用 MinGW 和 MSVC 构建的程序。
1.62.0 · sourcefn raw_arg<S: AsRef<OsStr>>(&mut self, text_to_append_as_is: S) -> &mut Command
 
fn raw_arg<S: AsRef<OsStr>>(&mut self, text_to_append_as_is: S) -> &mut Command
将字面量文本追加到命令行,无需任何引用或转义。
这对于将参数传递给 cmd.exe /c 很有用,它不遵循 CommandLineToArgvW 转义规则。
sourcefn async_pipes(&mut self, always_async: bool) -> &mut Command
 
fn async_pipes(&mut self, always_async: bool) -> &mut Command
🔬This is a nightly-only experimental API. (
windows_process_extensions_async_pipes #98289)当 process::Command 创建管道时,请求我们这边总是异步的。
默认情况下,process::Command 可以选择使用两端都打开的管道进行同步读取或写入操作。
通过使用 async_pipes(true),这种行为被覆盖,所以我们这边总是异步的。
这很重要,因为如果执行异步 I/O,则必须打开管道或文件以进行异步访问。
不管这个选项如何,发送到子进程的管道末端总是同步的。
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());