小编And*_*eno的帖子

无法在 Windows 中运行系统命令

Rust 代码是

use std::process::Command;

fn main() {
    if cfg!(target_os = "windows") {
        Command::new("cls").spawn().expect("cls command failed to start");
    } else {
        println!("Not windows");
    }
}
Run Code Online (Sandbox Code Playgroud)

错误是

PS C:\dev\Rust\testing> cargo run
   Compiling testing v0.1.0 (C:\dev\Rust\testing)
    Finished dev [unoptimized + debuginfo] target(s) in 0.95s
     Running `target\debug\testing.exe`
thread 'main' panicked at 'cls command failed to start: Os { code: 2, kind: NotFound, message: "The system cannot find the file 
specified." }', src\main.rs:5:37
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: process …
Run Code Online (Sandbox Code Playgroud)

windows rust

2
推荐指数
1
解决办法
1914
查看次数

标签 统计

rust ×1

windows ×1