Shell 为什么compgen命令可以在Linux终端中工作,而不能与process::command一起工作?

Shell 为什么compgen命令可以在Linux终端中工作,而不能与process::command一起工作?,shell,terminal,rust,Shell,Terminal,Rust,命令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); } 错

命令
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);
}
错误消息:

编译终端v0.1.0(file:///home/user/programmates/RUST/Terminal/terminal)
在0.66秒内完成开发[未优化+调试信息]目标
正在运行“目标/调试/终端”`
线程“main”在“未能执行进程:Os{code:2,kind:NotFound,消息:“没有这样的文件或目录”}”,libcore/result.rs:945:5时惊慌失措
注意:使用'RUST_BACKTRACE=1'运行回溯跟踪。

并非所有可用于shell的命令都可以通过
process::Command
运行;是一个bash,不能在它之外工作,因为它不是一个独立的程序-它嵌入在shell中

但是,通过向其传递以下内容,可以调用bash并执行
compgen


它是一个内置的shell而不是一个可执行文件,因此您需要调用shell。
Command::new("bash").args(&["-c", "compgen"])