@@ -10,10 +10,21 @@ import (
10
10
log "github.com/sirupsen/logrus"
11
11
)
12
12
13
+ // HostCommand wraps RunCommand() to inject environment variables.
14
+ // especially DDEV_EXECUTABLE, the full path to running ddev instance.
15
+ func HostCommand (name string , args ... string ) * exec.Cmd {
16
+ c := exec .Command (name , args ... )
17
+ ddevExecutable , _ := os .Executable ()
18
+ c .Env = append (os .Environ (),
19
+ "DDEV_EXECUTABLE=" + ddevExecutable ,
20
+ )
21
+ return c
22
+ }
23
+
13
24
// RunCommand runs a command on the host system.
14
25
// returns the stdout of the command and an err
15
26
func RunCommand (command string , args []string ) (string , error ) {
16
- out , err := exec . Command (
27
+ out , err := HostCommand (
17
28
command , args ... ,
18
29
).CombinedOutput ()
19
30
@@ -31,15 +42,15 @@ func RunCommandPipe(command string, args []string) (string, error) {
31
42
"Command" : command + " " + strings .Join (args [:], " " ),
32
43
}).Info ("Running " )
33
44
34
- cmd := exec . Command (command , args ... )
45
+ cmd := HostCommand (command , args ... )
35
46
stdoutStderr , err := cmd .CombinedOutput ()
36
47
return string (stdoutStderr ), err
37
48
}
38
49
39
50
// RunInteractiveCommand runs a command on the host system interactively, with stdin/stdout/stderr connected
40
51
// Returns error
41
52
func RunInteractiveCommand (command string , args []string ) error {
42
- cmd := exec . Command (command , args ... )
53
+ cmd := HostCommand (command , args ... )
43
54
cmd .Stdin = os .Stdin
44
55
cmd .Stdout = os .Stdout
45
56
cmd .Stderr = os .Stderr
@@ -57,7 +68,7 @@ func RunHostCommand(command string, args ...string) (string, error) {
57
68
if globalconfig .DdevVerbose {
58
69
output .UserOut .Printf ("RunHostCommand: " + command + " " + strings .Join (args , " " ))
59
70
}
60
- c := exec . Command (command , args ... )
71
+ c := HostCommand (command , args ... )
61
72
c .Stdin = os .Stdin
62
73
o , err := c .CombinedOutput ()
63
74
if globalconfig .DdevVerbose {
@@ -73,7 +84,7 @@ func RunHostCommandSeparateStreams(command string, args ...string) (string, erro
73
84
if globalconfig .DdevVerbose {
74
85
output .UserOut .Printf ("RunHostCommandSeparateStreams: " + command + " " + strings .Join (args , " " ))
75
86
}
76
- c := exec . Command (command , args ... )
87
+ c := HostCommand (command , args ... )
77
88
c .Stdin = os .Stdin
78
89
o , err := c .Output ()
79
90
if globalconfig .DdevVerbose {
0 commit comments