From a0edebea21a3375cd6ff3146e59ab035022f0fae Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Tue, 19 Mar 2019 19:58:58 +0100 Subject: [PATCH] Execute commands with env passthrough Signed-off-by: Knut Ahlers --- executor.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/executor.go b/executor.go index 3915cc8..b072480 100644 --- a/executor.go +++ b/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()