doc/readme #1
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;
|
use std::io::Write;
|
||||||
|
|
||||||
mod parser;
|
mod parser;
|
||||||
|
mod job;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut buffer = String::new();
|
let mut buffer = String::new();
|
||||||
let mut result_bytes_read: io::Result<usize>;
|
let mut result_bytes_read: io::Result<usize>;
|
||||||
let mut bytes_read: usize = 1;
|
let mut bytes_read: usize = 1;
|
||||||
let mut command_vec: Vec<String>;
|
let mut command_vec: Vec<String>;
|
||||||
|
let mut job: job::Job;
|
||||||
|
|
||||||
while bytes_read != 0 {
|
while bytes_read != 0 {
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
|
@ -25,7 +27,8 @@ fn main() {
|
||||||
bytes_read = result_bytes_read.unwrap();
|
bytes_read = result_bytes_read.unwrap();
|
||||||
if bytes_read != 0 {
|
if bytes_read != 0 {
|
||||||
command_vec = parser::parse(&buffer);
|
command_vec = parser::parse(&buffer);
|
||||||
println!("{:?}", command_vec);
|
job = job::build_job(&command_vec);
|
||||||
|
job.execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue