From 9b0a48cae2d8fa84b855641ed34a8fb28cf21eb5 Mon Sep 17 00:00:00 2001 From: jet2tlf Date: Fri, 31 May 2024 01:36:14 -0300 Subject: pass 8st stage --- cmd/myshell/main.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'cmd') diff --git a/cmd/myshell/main.go b/cmd/myshell/main.go index df4cfb1..b86b8ae 100644 --- a/cmd/myshell/main.go +++ b/cmd/myshell/main.go @@ -4,12 +4,11 @@ import ( "bufio" "fmt" "os" + "os/exec" "strconv" "strings" ) -var KnowCommands = map[string]int{"exit": 0, "echo": 1, "type": 2} - func main() { stdin := bufio.NewReader(os.Stdin) for { @@ -32,7 +31,14 @@ func main() { case "type": Type(command[1]) default: - fmt.Printf("%s: command not found\n", command[0]) + executable := exec.Command(command[0], command[1:]...) + executable.Stderr = os.Stderr + executable.Stdout = os.Stdout + + err := executable.Run() + if err != nil { + fmt.Printf("%s: command not found\n", command[0]) + } } } } @@ -67,6 +73,6 @@ func Type(command string) { return } } - fmt.Printf("%s not found\n", command) + fmt.Printf("%s: command not found\n", command) } } -- cgit v1.2.3