use std::io::{self, Read, Write};
use std::process::{Command, Output};
use std::str;
fn main() {
let mut stdin = io::stdin();
let mut stdout = io::stdout();
let mut input = [0; 24];
loop {
input = [0; 24];
print!("oursh> ");
stdout.lock().flush();
loop {
stdin.read(&mut input).expect("error reading STDIN");
let vec: Vec<&[u8]> = input.splitn(2, |b| *b == '\n' as u8).collect();
match &vec[..] {
[line, rest] => {
let program = str::from_utf8(&line).expect("error reading utf8");
let mut output = handle_program(program);
stdout.write(&output.stdout).expect("error writing to STDOUT");
break
}
_ => {},
}
}
}
}
fn handle_program(program: &str) -> Output {
Command::new(program)
.output()
.expect("error executing program")
}