1//! Helper module to detect subprocess exit code.
2
3use std::process::ExitStatus;
4
5#[cfg(not(unix))]
6pub fn get_exit_code(status: ExitStatus) -> Result<i32, String> {
7 status.code().ok_or("received no exit code from child process".into())
8}
9
10#[cfg(unix)]
11pub fn get_exit_code(status: ExitStatus) -> Result<i32, String> {
12 use std::os::unix::process::ExitStatusExt;
13 match status.code() {
14 Some(code: i32) => Ok(code),
15 None => match status.signal() {
16 Some(signal: i32) => Err(format!("child process exited with signal {}", signal)),
17 None => Err("child process exited with unknown signal".into()),
18 },
19 }
20}
21