diff --git a/src/job.rs b/src/job.rs new file mode 100644 index 0000000..3177ee4 --- /dev/null +++ b/src/job.rs @@ -0,0 +1,28 @@ +use std::io::Result; +use std::process::{Command, Child, ExitStatus}; + +pub struct Job { + id: usize, + argv: Vec, + is_background: bool, +} + +pub fn build_job(argv: &Vec) -> Job { + Job { + id: 1, + argv: argv.to_vec(), + is_background: false, + } +} + +impl Job { + pub fn execute(&self) -> ExitStatus { + let mut argv_iter = self.argv.iter(); + + let child_result: Result = Command::new(argv_iter.next().unwrap()) + .args(argv_iter) + .spawn(); + + child_result.unwrap().wait().unwrap() + } +} diff --git a/src/main.rs b/src/main.rs index 8c9d1ab..d273a5e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,12 +2,14 @@ use std::io; use std::io::Write; mod parser; +mod job; fn main() { let mut buffer = String::new(); let mut result_bytes_read: io::Result; let mut bytes_read: usize = 1; let mut command_vec: Vec; + let mut job: job::Job; while bytes_read != 0 { buffer.clear(); @@ -25,7 +27,8 @@ fn main() { bytes_read = result_bytes_read.unwrap(); if bytes_read != 0 { command_vec = parser::parse(&buffer); - println!("{:?}", command_vec); + job = job::build_job(&command_vec); + job.execute(); } } }