package cmds import ( "fmt" "os" "os/exec" "path" "gosh/global" ) func External(args []string) int { cmd := "" found := false for i := range global.Paths { cmd = path.Join(global.Paths[i], args[0]) if _, err := os.Stat(cmd); err == nil { found = true break } } if found { cmd := exec.Command(cmd, args[1:]...) cmd.Stdin = os.Stdin cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr err := cmd.Run() if exitErr, ok := err.(*exec.ExitError); ok { return exitErr.ExitCode() } return 0 } fmt.Fprintf(os.Stderr, "%s: Command not found\n", args[0]) return 1 }