diff options
| author | jet2tlf <jet2tlf@gmail.com> | 2024-05-31 04:36:14 +0000 |
|---|---|---|
| committer | jet2tlf <jet2tlf@gmail.com> | 2024-05-31 04:36:14 +0000 |
| commit | 9b0a48cae2d8fa84b855641ed34a8fb28cf21eb5 (patch) | |
| tree | fc7ab92a88a91d6727f311d17740a19f55150ed1 /cmd | |
| parent | 4af866a988e2cc59482ea35b3b22f8c5ac802862 (diff) | |
| download | shell-go-9b0a48cae2d8fa84b855641ed34a8fb28cf21eb5.tar.gz shell-go-9b0a48cae2d8fa84b855641ed34a8fb28cf21eb5.zip | |
pass 8st stage
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/myshell/main.go | 14 |
1 files changed, 10 insertions, 4 deletions
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) } } |