Source file
src/cmd/dist/exec.go
1
2
3
4
5 package main
6
7 import (
8 "os/exec"
9 "strings"
10 )
11
12
13 func setDir(cmd *exec.Cmd, dir string) {
14 cmd.Dir = dir
15 if cmd.Env != nil {
16
17 setEnv(cmd, "PWD", dir)
18 }
19 }
20
21
22 func setEnv(cmd *exec.Cmd, key, value string) {
23 cmd.Env = append(cmd.Environ(), key+"="+value)
24 }
25
26
27 func unsetEnv(cmd *exec.Cmd, key string) {
28 cmd.Env = cmd.Environ()
29
30 prefix := key + "="
31 newEnv := []string{}
32 for _, entry := range cmd.Env {
33 if strings.HasPrefix(entry, prefix) {
34 continue
35 }
36 newEnv = append(newEnv, entry)
37
38 }
39 cmd.Env = newEnv
40 }
41
View as plain text