Why does the compgen command work in the Linux terminal but not with process::Command?

user103766

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.
ljedrz

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Linux. Why does my Linux command work on the terminal but it doesn't work in a script

From Dev

Terminal command does not work in PhpStorm

From Dev

Why does this command work on my terminal but not in my code?

From Dev

Why does my mac terminal command NOT work in a shell script?

From Dev

Why does command not work with a command beginning with assignment?

From Dev

Why does the echo command do not work with at command?

From Dev

Understand `compgen` builtin command

From Dev

Why does this javac command not work?

From Dev

Why does a command not work as alias?

From Dev

Why does this grep command not work?

From Dev

unix find command in terminal does not work

From Dev

How does the exit command work on a Unix terminal?

From Dev

Linux terminal command for tracing threads and system calls in a process

From Dev

How to know the process of the terminal which is running in Linux command?

From Java

How does the 'ls' command work in Linux/Unix?

From Dev

Why does the same command work differently from CMD vs Process.Start()?

From Dev

Why does command injection not work in this example?

From Java

Why does this sed command to match number not work?

From Dev

Why does this ffmpeg command work in bash and not zsh?

From Dev

Why does the jobs command not work in shell script?

From Dev

Why does the second grep command not work?

From Dev

Why does this command work for logging script output?

From Dev

Why does this Powershell subexpression operator command not work?

From Dev

Why does Docker "ancestry" API command not work?

From Dev

Why does my exit() command not work in python?

From Dev

Why does my xdotool key command not work?

From Dev

Why does `cd` command not work via SSH?

From Dev

why does this IF statement work on the command line but not in a script?

From Dev

why does the if command doesnt work properly

Related Related

  1. 1

    Linux. Why does my Linux command work on the terminal but it doesn't work in a script

  2. 2

    Terminal command does not work in PhpStorm

  3. 3

    Why does this command work on my terminal but not in my code?

  4. 4

    Why does my mac terminal command NOT work in a shell script?

  5. 5

    Why does command not work with a command beginning with assignment?

  6. 6

    Why does the echo command do not work with at command?

  7. 7

    Understand `compgen` builtin command

  8. 8

    Why does this javac command not work?

  9. 9

    Why does a command not work as alias?

  10. 10

    Why does this grep command not work?

  11. 11

    unix find command in terminal does not work

  12. 12

    How does the exit command work on a Unix terminal?

  13. 13

    Linux terminal command for tracing threads and system calls in a process

  14. 14

    How to know the process of the terminal which is running in Linux command?

  15. 15

    How does the 'ls' command work in Linux/Unix?

  16. 16

    Why does the same command work differently from CMD vs Process.Start()?

  17. 17

    Why does command injection not work in this example?

  18. 18

    Why does this sed command to match number not work?

  19. 19

    Why does this ffmpeg command work in bash and not zsh?

  20. 20

    Why does the jobs command not work in shell script?

  21. 21

    Why does the second grep command not work?

  22. 22

    Why does this command work for logging script output?

  23. 23

    Why does this Powershell subexpression operator command not work?

  24. 24

    Why does Docker "ancestry" API command not work?

  25. 25

    Why does my exit() command not work in python?

  26. 26

    Why does my xdotool key command not work?

  27. 27

    Why does `cd` command not work via SSH?

  28. 28

    why does this IF statement work on the command line but not in a script?

  29. 29

    why does the if command doesnt work properly

HotTag

Archive