Possibilité d'exécuter des commandes !

This commit is contained in:
Ahurac 2023-12-10 22:29:07 +01:00
parent 9022d04ca9
commit 2e45fabc68
2 changed files with 25 additions and 1 deletions

23
src/job.rs Normal file
View file

@ -0,0 +1,23 @@
use std::process::{
Command,
ExitStatus,
};
use std::io::{
Result,
Error,
ErrorKind,
};
pub fn execute(mut argv: Vec<String>) -> Result<ExitStatus> {
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"))
}
}

View file

@ -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());
}
}