mirror of https://github.com/Hilbis/Hilbish
Compare commits
2 Commits
2de1d26b39
...
404cc05b30
Author | SHA1 | Date |
---|---|---|
sammyette | 404cc05b30 | |
sammyette | 72324c27de |
25
exec.go
25
exec.go
|
@ -259,6 +259,7 @@ func execCommand(cmd string, strms *streams) (io.Writer, io.Writer, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
interp.StdIO(strms.stdin, strms.stdout, strms.stderr)(runner)
|
interp.StdIO(strms.stdin, strms.stdout, strms.stderr)(runner)
|
||||||
|
interp.Env(nil)(runner)
|
||||||
|
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
printer := syntax.NewPrinter()
|
printer := syntax.NewPrinter()
|
||||||
|
@ -371,7 +372,7 @@ func execHandle(bg bool) interp.ExecHandlerFunc {
|
||||||
return interp.NewExitStatus(exitcode)
|
return interp.NewExitStatus(exitcode)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := lookpath(args[0])
|
path, err := lookpath(args[0])
|
||||||
if err == errNotExec {
|
if err == errNotExec {
|
||||||
return execError{
|
return execError{
|
||||||
typ: "not-executable",
|
typ: "not-executable",
|
||||||
|
@ -392,15 +393,16 @@ func execHandle(bg bool) interp.ExecHandlerFunc {
|
||||||
killTimeout := 2 * time.Second
|
killTimeout := 2 * time.Second
|
||||||
// from here is basically copy-paste of the default exec handler from
|
// from here is basically copy-paste of the default exec handler from
|
||||||
// sh/interp but with our job handling
|
// sh/interp but with our job handling
|
||||||
path, err := interp.LookPathDir(hc.Dir, hc.Env, args[0])
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintln(hc.Stderr, err)
|
|
||||||
return interp.NewExitStatus(127)
|
|
||||||
}
|
|
||||||
|
|
||||||
env := hc.Env
|
env := hc.Env
|
||||||
envList := make([]string, 0, 64)
|
envList := make([]string, 0, 64)
|
||||||
env.Each(func(name string, vr expand.Variable) bool {
|
env.Each(func(name string, vr expand.Variable) bool {
|
||||||
|
if name == "PATH" {
|
||||||
|
pathEnv := os.Getenv("PATH")
|
||||||
|
envList = append(envList, "PATH="+pathEnv)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
if !vr.IsSet() {
|
if !vr.IsSet() {
|
||||||
// If a variable is set globally but unset in the
|
// If a variable is set globally but unset in the
|
||||||
// runner, we need to ensure it's not part of the final
|
// runner, we need to ensure it's not part of the final
|
||||||
|
@ -418,6 +420,7 @@ func execHandle(bg bool) interp.ExecHandlerFunc {
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|
||||||
cmd := exec.Cmd{
|
cmd := exec.Cmd{
|
||||||
Path: path,
|
Path: path,
|
||||||
Args: args,
|
Args: args,
|
||||||
|
@ -500,7 +503,7 @@ func handleExecErr(err error) (exit uint8) {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
func lookpath(file string) error { // custom lookpath function so we know if a command is found *and* is executable
|
func lookpath(file string) (string, error) { // custom lookpath function so we know if a command is found *and* is executable
|
||||||
var skip []string
|
var skip []string
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
skip = []string{"./", "../", "~/", "C:"}
|
skip = []string{"./", "../", "~/", "C:"}
|
||||||
|
@ -509,20 +512,20 @@ func lookpath(file string) error { // custom lookpath function so we know if a c
|
||||||
}
|
}
|
||||||
for _, s := range skip {
|
for _, s := range skip {
|
||||||
if strings.HasPrefix(file, s) {
|
if strings.HasPrefix(file, s) {
|
||||||
return findExecutable(file, false, false)
|
return file, findExecutable(file, false, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, dir := range filepath.SplitList(os.Getenv("PATH")) {
|
for _, dir := range filepath.SplitList(os.Getenv("PATH")) {
|
||||||
path := filepath.Join(dir, file)
|
path := filepath.Join(dir, file)
|
||||||
err := findExecutable(path, true, false)
|
err := findExecutable(path, true, false)
|
||||||
if err == errNotExec {
|
if err == errNotExec {
|
||||||
return err
|
return "", err
|
||||||
} else if err == nil {
|
} else if err == nil {
|
||||||
return nil
|
return path, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return os.ErrNotExist
|
return "", os.ErrNotExist
|
||||||
}
|
}
|
||||||
|
|
||||||
func splitInput(input string) ([]string, string) {
|
func splitInput(input string) ([]string, string) {
|
||||||
|
|
Loading…
Reference in New Issue