Skip to content

Commit 4c9fc24

Browse files
committed
client: use os/exec/Cmd.Environ() instead of os.Environ()
Don't set Env if not set; the default is already handled if it's nil; from the documentation: https://pkg.go.dev/os/[email protected]#Cmd.Env // If Env is nil, the new process uses the current process's // environment. Use `os/exec/Cmd.Environ()` instead of `os.Environ()`, which was added in go1.19, and handles additional environment variables, such as `PWD` on POSIX systems, and `SYSTEMROOT` on Windows. https://pkg.go.dev/os/[email protected]#Cmd.Environ Also remove a redundant `fmt.Sprintf()`, as we're only concatenating strings. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent f8e94d9 commit 4c9fc24

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

client/command.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package client
22

33
import (
4-
"fmt"
54
"io"
65
"os"
76
"os/exec"
@@ -30,10 +29,9 @@ func NewShellProgramFuncWithEnv(name string, env *map[string]string) ProgramFunc
3029

3130
func createProgramCmdRedirectErr(commandName string, args []string, env *map[string]string) *exec.Cmd {
3231
programCmd := exec.Command(commandName, args...)
33-
programCmd.Env = os.Environ()
3432
if env != nil {
3533
for k, v := range *env {
36-
programCmd.Env = append(programCmd.Env, fmt.Sprintf("%s=%s", k, v))
34+
programCmd.Env = append(programCmd.Environ(), k+"="+v)
3735
}
3836
}
3937
programCmd.Stderr = os.Stderr

0 commit comments

Comments
 (0)