-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Closed
Labels
Description
Using go version go1.11.1 linux/amd64 with default env I run the following code (simplified for the ticket, added extra fmt.Print*)
cmdArgs = <-stdin
log.Printf("Got %v to run", cmdArgs)
cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...)
ret, err = cmd.CombinedOutput()
fmt.Println(ret)
Expected result --
Got [go build -o=/abs/path/to/output/HelloWorld -a /abs/path/to/code/HelloWorld/] to run
Actual result --
Got [go build -o=/abs/path/to/output/HelloWorld -a /abs/path/to/code/HelloWorld/] to run
go: directory ../HelloWorld/ outside available modules
Somehow, exec.Command transforms an absolute build path to relative (specifically, relative to current software working dir), making me think that when the program runs, additional go execs have the same execution environment.
Appending cmd.Dir = "/abs/path/to/code/HelloWorld/" fixes the issue, but I would like to get around this.
P.S. Since build path is absolute, obviously, I'm using go mod.