mirror of
https://github.com/Luzifer/update-gotools.git
synced 2024-12-22 04:41:20 +00:00
Execute commands with env passthrough
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
a84766069d
commit
a0edebea21
1 changed files with 6 additions and 7 deletions
13
executor.go
13
executor.go
|
@ -5,10 +5,11 @@ import (
|
|||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/Luzifer/go_helpers/str"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/Luzifer/go_helpers/env"
|
||||
"github.com/Luzifer/go_helpers/str"
|
||||
)
|
||||
|
||||
func executeCommands(logEntry *log.Entry, commands [][]string) error {
|
||||
|
@ -27,14 +28,12 @@ func executeCommands(logEntry *log.Entry, commands [][]string) error {
|
|||
}
|
||||
|
||||
func executeCommand(command []string, stdout, stderr io.Writer, cwd string) error {
|
||||
env := []string{
|
||||
strings.Join([]string{"GOPATH", cfgFile.GoPath}, "="),
|
||||
strings.Join([]string{"PATH", os.Getenv("PATH")}, "="),
|
||||
}
|
||||
e := env.ListToMap(os.Environ())
|
||||
e["GOPATH"] = cfgFile.GoPath
|
||||
|
||||
cmd := exec.Command(command[0], command[1:]...)
|
||||
cmd.Dir = cwd
|
||||
cmd.Env = env
|
||||
cmd.Env = env.MapToList(e)
|
||||
cmd.Stdout = stdout
|
||||
cmd.Stderr = stderr
|
||||
return cmd.Run()
|
||||
|
|
Loading…
Reference in a new issue