Here is a tiny program:
use std::env;
use std::process;
fn main() {
let code: i32 = env::args().skip(1).next().unwrap().parse().unwrap();
println!("Got {}", code);
process::exit(code);
}
Here are two runs on Linux:
: crr.sh 0
Finished release [optimized] target(s) in 0.0 secs
Running `target/release/app 0`
Got 0
: crr.sh 1
Finished release [optimized] target(s) in 0.0 secs
Running `target/release/app 1`
Got 1
(crr.sh
& crr.bat
just do cargo run --release
)
But on Windows it is different:
V:\tmp\app>cargo run --release -- 0
Finished release [optimized] target(s) in 0.11 secs
Running `target\release\app.exe 0`
Got 0
V:\tmp\app>crr 1
V:\tmp\app>cargo run --release -- 1
Finished release [optimized] target(s) in 0.10 secs
Running `target\release\app.exe 1`
Got 1
error: process didn't exit successfully: `target\release\app.exe 1` (exit code: 1)
I am trying to write a command line program on Windows and ideally I'd like to be able to return an int to the OS so that people can use it as %errorlevel%
in .bat
files without the extra error message. Just a nice to have though.