The command compgen
works fine in the Linux Terminal, but causes a panic when using Command::new.
My code:
use std::process::Command;
fn main() {
let status = Command::new("compgen")
.status()
.expect("failed to execute process");
println!("process exited with: {}", status);
}
The error message:
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.
Not all commands available to the shell are runnable with process::Command
; compgen
is a bash builtin command and doesn't work outside of it, because it is not a standalone program - it is embedded within the shell.
It is, however, possible to invoke bash and execute compgen
by passing the following option to it:
Command::new("bash").args(&["-c", "compgen"])
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments