|
@ -1,7 +1,7 @@ |
|
|
|
|
|
use std::io::ErrorKind::NotFound;
|
|
|
use std::process::Command;
|
|
|
use std::process::Command;
|
|
|
|
|
|
|
|
|
use crate::error::ShellError;
|
|
|
use crate::error::ShellError;
|
|
|
use crate::error::ShellError::Execute;
|
|
|
|
|
|
use crate::parse::parse_line;
|
|
|
use crate::parse::parse_line;
|
|
|
|
|
|
|
|
|
pub fn interpret(line: &str) -> Result<(), ShellError> {
|
|
|
pub fn interpret(line: &str) -> Result<(), ShellError> {
|
|
@ -22,10 +22,15 @@ fn execute(mut command: Command) -> Result<(), ShellError> { |
|
|
match command.spawn() {
|
|
|
match command.spawn() {
|
|
|
Ok(mut child) => {
|
|
|
Ok(mut child) => {
|
|
|
if let Err(err) = child.wait() {
|
|
|
if let Err(err) = child.wait() {
|
|
|
return Err(Execute(err.to_string()));
|
|
|
|
|
|
|
|
|
return Err(ShellError::ExecuteFailure(err.to_string()));
|
|
|
}
|
|
|
}
|
|
|
Ok(())
|
|
|
Ok(())
|
|
|
}
|
|
|
}
|
|
|
Err(err) => Err(Execute(err.to_string())),
|
|
|
|
|
|
|
|
|
Err(err) => {
|
|
|
|
|
|
if err.kind() == NotFound {
|
|
|
|
|
|
return Err(ShellError::NotFound(command));
|
|
|
|
|
|
}
|
|
|
|
|
|
Err(ShellError::ExecuteFailure(err.to_string()))
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|