命令compgen
在Linux终端中运行正常,但在使用Command :: new时会引起恐慌。
我的代码:
use std::process::Command;
fn main() {
let status = Command::new("compgen")
.status()
.expect("failed to execute process");
println!("process exited with: {}", status);
}
错误消息:
Compiling terminal v0.1.0 (file:///home/user/programmates/RUST/Terminal/terminal)
Finished dev [unoptimized + debuginfo] target(s) in 0.66 secs
Running `target/debug/terminal`
thread 'main' panicked at 'failed to execute process: Os { code: 2, kind: NotFound, message: "No such file or directory" }', libcore/result.rs:945:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.
答案 0 :(得分:1)
并非所有shell可用的命令都可以使用process::Command
运行; compgen
是一个bash builtin command,并且不会在它之外工作,因为它不是一个独立的程序 - 它嵌入在shell中。
然而,可以通过将以下option传递给它来调用bash并执行compgen
:
Command::new("bash").args(&["-c", "compgen"])