Attempt to run a process if command isn't a builtin
This commit is contained in:
parent
7eaf3b933c
commit
6500677f35
18
src/main.rs
18
src/main.rs
@ -1,6 +1,6 @@
|
||||
use std::{
|
||||
io::{self, Write},
|
||||
path::{Component, Path, PathBuf},
|
||||
path::{Component, Path, PathBuf}, process::Command,
|
||||
};
|
||||
|
||||
use clap::Parser;
|
||||
@ -157,7 +157,21 @@ fn main() {
|
||||
println!("exit");
|
||||
println!("help");
|
||||
}
|
||||
_ => println!("psh: {}: command not found", cmd[0]),
|
||||
_ => {
|
||||
let path = if cmd[0].starts_with(".") || cmd[0].starts_with("~") || cmd[0].starts_with("/") {
|
||||
cmd[0].to_string()
|
||||
} else {
|
||||
format!("/bin/{}", cmd[0])
|
||||
};
|
||||
let mut proc = match Command::new(path).spawn() {
|
||||
Ok(x) => x,
|
||||
Err(e) => {
|
||||
println!("psh: {}: {}", cmd[0], e);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
let _ = proc.wait().unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user