How to display error from Command::new().output()

Viewed 36

How can I display the stderr from Command::new().output()?

If I do it like this

let result = Command::new("mkdir").args(["test"]).output();

I can check if it was successful:

if result.status.success() == false {
    ...
}

but if I print the whole thing it looks like this:

Output {
    status: ExitStatus(
        unix_wait_status(
            256,
        ),
    ),
    stdout: "",
    stderr: "mkdir: cannot create directory ‘testing’: File exists\n",
}

And I just need the stderr. How can I do that?

0 Answers
Related