Hi *,
I'd like to run a script in a subdirectory and also have the working directory for it there.
These are the snippets I tried:
1.)
//fork/exec hooks/script.sh: no such file or directory
cmd := exec.Command("hooks/script.sh")
cmd.Dir = "hooks"
2.)
//exec: "script.sh": executable file not found in $PATH
cmd := exec.Command("script.sh")
cmd.Dir = "hooks"
3.)
// Working:
cmd := exec.Command("hooks/script.sh")
cmd.Dir = "hooks"
cmd.Path = "script.sh"
cmd.Args[0] = "script.sh"
4.)
// Working
cmd := exec.Cmd{
Path: "script.sh"
Args: []string{"script.sh"},
Dir: "hooks",
}
5.)
// Working
absexe, _ := filepath.Abs("hooks/script.sh")
cmd := exec.Command(absexe)
cmd.Dir = "hooks"
Now I understand that 1) shouldn't work. But I would've expected 2) to work. However in:
it seems like the error is set upon calling Command and sticks around even though I'm setting Dir later on.
Is this the intended behavior? Shouldn't the LookPath() call in Command() maybe happen later and take Dir into account?
Cheers,
Andy