You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

31 lines
729 B

use std::process::Command;
use crate::error::ShellError;
use crate::error::ShellError::Execute;
use crate::parse::parse_line;
pub fn interpret(line: &str) -> Result<(), ShellError> {
if line.is_empty() {
return Err(ShellError::EmptyLine);
}
let (keyword, args) = parse_line(line);
let mut command = Command::new(keyword);
command.args(args);
execute(command)?;
Ok(())
}
fn execute(mut command: Command) -> Result<(), ShellError> {
match command.spawn() {
Ok(mut child) => {
if let Err(err) = child.wait() {
return Err(Execute(err.to_string()));
}
Ok(())
}
Err(err) => Err(Execute(err.to_string())),
}
}