Open
Description
Hi. Normally, Rust makes it difficult to accidentally write code which ignores errors. This is one of its great strengths. However, the std::process
API requires the user to explicitly check the process exit status.
(This issue is about the return value from wait()
. I am filing another one about output()
. See also #70186 which is about the return value from spawn()
.)
Here's a demo of the problem.
use std::process::*;
fn main() {
let command = ["ls","--no-such-option"];
Command::new(command[0])
.args(&command[1..])
.spawn().expect("Failed spawn")
.wait().expect("Failed wait");
println!("I ran {:?}", &command);
println!("All went well!")
}
It produces this output:
Compiling playground v0.0.1 (/playground)
Finished dev [unoptimized + debuginfo] target(s) in 0.98s
Running `target/debug/playground`
ls: unrecognized option '--no-such-option'
Try 'ls --help' for more information.
Standard Output
I ran ["ls", "--no-such-option"]
All went well!
This is not optimal. I think making ExitStatus
be #[must_use]
would be the best way to address this. The code above would then generate a compiler error. The programmer would be prompted to make an actual decision about the exit status.