From 8c2465b09338d4fbd837ebd83220bbc264b2141f Mon Sep 17 00:00:00 2001 From: Ahurac Date: Mon, 11 Dec 2023 13:20:24 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Code=20de=20sortie=20:=20impl=C3=A9mentatio?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 13dd9f9..14b3743 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,8 @@ -use std::process::exit; +use std::io::Result; +use std::process::{ + ExitStatus, + exit, +}; mod input; mod output; @@ -9,6 +13,8 @@ fn main() { let mut buffer = input::Buffer::new(); let mut bytes_read: usize = 1; let mut argv: Option>; + let mut exit_status: Result; + let mut exit_code: i32 = 0; while bytes_read != 0 { output::print_ps1(); @@ -16,11 +22,22 @@ fn main() { argv = buffer.parse(); if argv.is_some() { - let _ = job::execute(argv.unwrap()); + exit_status = job::execute(argv.unwrap()); + + if exit_status.is_ok() { + let exit_status = exit_status.unwrap(); + + if exit_status.code().is_some() { + exit_code = exit_status.code().unwrap(); + } else { + exit_code = 1; + } + } else { + exit_code = 1; + } } } println!(); - - exit(0); + exit(exit_code); } From 259e74e629232ca4beddbb5ea7c4dc81f7b2630f Mon Sep 17 00:00:00 2001 From: Ahurac Date: Mon, 11 Dec 2023 13:23:04 +0100 Subject: [PATCH 2/2] README : coche case `Code de sortie des processus` --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6d9b1be..5f9f82a 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ ## To-do - [x] Read commands from `stdin` -- [ ] Exit with last child termination code +- [x] Exit with last child termination code - [ ] Handle background jobs - [ ] Handle pipes - [ ] Handle double quotes