mirror of
https://github.com/Luzifer/update-gotools.git
synced 2024-12-22 12:51: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"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/Luzifer/go_helpers/str"
|
|
||||||
log "github.com/sirupsen/logrus"
|
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 {
|
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 {
|
func executeCommand(command []string, stdout, stderr io.Writer, cwd string) error {
|
||||||
env := []string{
|
e := env.ListToMap(os.Environ())
|
||||||
strings.Join([]string{"GOPATH", cfgFile.GoPath}, "="),
|
e["GOPATH"] = cfgFile.GoPath
|
||||||
strings.Join([]string{"PATH", os.Getenv("PATH")}, "="),
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd := exec.Command(command[0], command[1:]...)
|
cmd := exec.Command(command[0], command[1:]...)
|
||||||
cmd.Dir = cwd
|
cmd.Dir = cwd
|
||||||
cmd.Env = env
|
cmd.Env = env.MapToList(e)
|
||||||
cmd.Stdout = stdout
|
cmd.Stdout = stdout
|
||||||
cmd.Stderr = stderr
|
cmd.Stderr = stderr
|
||||||
return cmd.Run()
|
return cmd.Run()
|
||||||
|
|
Loading…
Reference in a new issue