Fonction execute
This commit is contained in:
parent
5cd4fc2632
commit
99ce65ad9a
2 changed files with 32 additions and 1 deletions
28
src/job.rs
Normal file
28
src/job.rs
Normal file
|
@ -0,0 +1,28 @@
|
|||
use std::io::Result;
|
||||
use std::process::{Command, Child, ExitStatus};
|
||||
|
||||
pub struct Job {
|
||||
id: usize,
|
||||
argv: Vec<String>,
|
||||
is_background: bool,
|
||||
}
|
||||
|
||||
pub fn build_job(argv: &Vec<String>) -> 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<Child> = Command::new(argv_iter.next().unwrap())
|
||||
.args(argv_iter)
|
||||
.spawn();
|
||||
|
||||
child_result.unwrap().wait().unwrap()
|
||||
}
|
||||
}
|
|
@ -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<usize>;
|
||||
let mut bytes_read: usize = 1;
|
||||
let mut command_vec: Vec<String>;
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue