小编12t*_*all的帖子

为什么我不能在 Rust 中将 `Stdio::piped()` 与 windows `cmd.exe` 一起使用?

当我尝试cmd.exe通过以下代码开始时:

use std::process::{Command, Stdio};
use std::io::{BufRead, Write, BufReader};

fn main() {
    let mut child_cmd = Command::new("cmd.exe")  
        // seems it work well with `/bin/bash` in Linux
        .stdin(Stdio::piped())
        .stdout(Stdio::piped())   // Error emitted here. 
        .spawn()
        .unwrap();   
    // do sth. else
}
Run Code Online (Sandbox Code Playgroud)

我想将输出重定向到管道,但它总是报告The process tried to write to a nonexistent pipe;当我删除时.stdout(Stdio::piped()),没有抛出错误。为什么会发生这种情况?

windows cmd process rust

5
推荐指数
1
解决办法
53
查看次数

标签 统计

cmd ×1

process ×1

rust ×1

windows ×1