diff --git a/src/uu/stdbuf/src/stdbuf.rs b/src/uu/stdbuf/src/stdbuf.rs index e566439f0..8c20cc39a 100644 --- a/src/uu/stdbuf/src/stdbuf.rs +++ b/src/uu/stdbuf/src/stdbuf.rs @@ -159,18 +159,26 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let mut process = match command.spawn() { Ok(process) => process, - Err(e) if e.kind() == std::io::ErrorKind::PermissionDenied => { - return Err(USimpleError::new( - 126, - "failed to execute process: Permission denied", - )); - } - Err(e) => { - return Err(USimpleError::new( - 1, - format!("failed to execute process: {}", e), - )); - } + Err(e) => match e.kind() { + std::io::ErrorKind::PermissionDenied => { + return Err(USimpleError::new( + 126, + "failed to execute process: Permission denied", + )); + } + std::io::ErrorKind::NotFound => { + return Err(USimpleError::new( + 127, + "failed to execute process: No such file or directory", + )); + } + _ => { + return Err(USimpleError::new( + 1, + format!("failed to execute process: {}", e), + )); + } + }, }; let status = process.wait().map_err_context(String::new)?; diff --git a/tests/by-util/test_stdbuf.rs b/tests/by-util/test_stdbuf.rs index c2d7f9121..4bee30fab 100644 --- a/tests/by-util/test_stdbuf.rs +++ b/tests/by-util/test_stdbuf.rs @@ -20,6 +20,16 @@ fn test_permission() { .stderr_contains("Permission denied"); } +#[test] +fn test_no_such() { + new_ucmd!() + .arg("-o1") + .arg("no_such") + .fails() + .code_is(127) + .stderr_contains("No such file or directory"); +} + #[cfg(all(not(target_os = "windows"), not(target_os = "openbsd")))] #[test] fn test_stdbuf_unbuffered_stdout() {