Skip to content

Commit

Permalink
improvement: add error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
nezzzumi committed Feb 6, 2023
1 parent 2e67a5b commit d86c2f5
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::HashMap;
use std::env;
use std::process;
use std::process::exit;
use std::process::Stdio;
use std::time;

Expand All @@ -17,23 +18,31 @@ fn execute(program: String, args: &[String]) -> Vec<TimeResult> {
for _ in 0..EXECUTIONS {
let now = time::Instant::now();

let exit_code = process::Command::new(program.clone())
let mut command = process::Command::new(program.clone());

command
.args(args)
.stderr(Stdio::null())
.stdout(Stdio::null())
.status()
.unwrap()
.code()
.unwrap();
.stdout(Stdio::null());

let status = command.status();

let time_elapsed = now.elapsed();
match status {
Ok(val) => {
let time_elapsed = now.elapsed();

let result = TimeResult {
exit_code,
time: time_elapsed.as_secs_f32(),
};
let result = TimeResult {
exit_code: val.code().unwrap(),
time: time_elapsed.as_secs_f32(),
};

results.push(result);
results.push(result);
}
Err(err) => {
eprintln!("error: an error occurred when running the command '{program}': {err}");
exit(127)
}
}
}
return results;
}
Expand Down

0 comments on commit d86c2f5

Please sign in to comment.