From 6500677f35dfdaf18d5128ef89efd7adcb64380b Mon Sep 17 00:00:00 2001 From: pjht Date: Fri, 8 Nov 2024 14:58:58 -0600 Subject: [PATCH] Attempt to run a process if command isn't a builtin --- src/main.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 01debb3..5141a96 100644 --- a/src/main.rs +++ b/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(); + } } } }