summaryrefslogtreecommitdiff
path: root/cmds/external.go
blob: da2429192da48057c8c3d16dbac038269ee5a11d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package cmds

import (
	"fmt"
	"os"
	"os/exec"
	"path"

	"gosh/global"
)

func External(args []string) {
	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.Stdout = os.Stdout
		cmd.Stderr = os.Stderr
		
		cmd.Run()
		return
	}
	fmt.Fprintf(os.Stderr, "%s: Command not found\n", args[0])
}