From 2e45fabc681fe56c2feac0f4a255f84de73eff13 Mon Sep 17 00:00:00 2001 From: Ahurac Date: Sun, 10 Dec 2023 22:29:07 +0100 Subject: [PATCH] =?UTF-8?q?Possibilit=C3=A9=20d'ex=C3=A9cuter=20des=20comm?= =?UTF-8?q?andes=20!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/job.rs | 23 +++++++++++++++++++++++ src/main.rs | 3 ++- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/job.rs diff --git a/src/job.rs b/src/job.rs new file mode 100644 index 0000000..028ed75 --- /dev/null +++ b/src/job.rs @@ -0,0 +1,23 @@ +use std::process::{ + Command, + ExitStatus, +}; +use std::io::{ + Result, + Error, + ErrorKind, +}; + +pub fn execute(mut argv: Vec) -> Result { + let mut command = Command::new(&argv[0]); + argv.remove(0); + command.args(argv); + + let child = command.spawn(); + + if child.is_ok() { + child.unwrap().wait() + } else { + Err(Error::new(ErrorKind::Other, "failed to spawn child process")) + } +} diff --git a/src/main.rs b/src/main.rs index 8458530..13dd9f9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ use std::process::exit; mod input; mod output; mod parser; +mod job; fn main() { let mut buffer = input::Buffer::new(); @@ -15,7 +16,7 @@ fn main() { argv = buffer.parse(); if argv.is_some() { - println!("{:?}", argv.unwrap()); + let _ = job::execute(argv.unwrap()); } }