@@ -12,7 +12,9 @@ import (
12
12
"github.com/sirupsen/logrus"
13
13
)
14
14
15
+ // the default windows shell must be cmd.exe for compatibility with older Windows versions
15
16
const defaultWindowsShell = "cmd.exe"
17
+
16
18
const defaultUnixShell = "sh"
17
19
18
20
type SystemAPI interface {
@@ -86,7 +88,15 @@ func (rm *RunnerMock) Run(execContext *Context) error {
86
88
}
87
89
88
90
func (sr SystemRunner ) Run (execContext * Context ) error {
89
- tmpFile , err := ioutil .TempFile (os .TempDir (), "taco-" )
91
+ tmpPattern := "taco-*"
92
+ if runtime .GOOS == "windows" {
93
+ if execContext .Shell == defaultWindowsShell {
94
+ tmpPattern = "taco-*.cmd"
95
+ } else {
96
+ tmpPattern = "taco-*.ps1"
97
+ }
98
+ }
99
+ tmpFile , err := ioutil .TempFile (os .TempDir (), tmpPattern )
90
100
if err != nil {
91
101
return err
92
102
}
@@ -130,16 +140,34 @@ func (sr SystemRunner) setWorkingDir(cmd *exec.Cmd, execContext *Context) {
130
140
}
131
141
132
142
func (sr SystemRunner ) createCmd (execContext * Context , tmpFile * os.File ) (cmd * exec.Cmd , err error ) {
133
- rawCmds := strings .Join (execContext .Cmds , "\n " )
143
+ prelude := ""
144
+ newLine := "\n "
145
+
146
+ if runtime .GOOS == "windows" {
147
+ newLine = "\r \n "
148
+ if execContext .Shell == defaultWindowsShell {
149
+ prelude = "@echo off" + newLine
150
+ }
151
+ }
152
+
153
+ rawCmds := prelude + strings .Join (execContext .Cmds , newLine )
154
+
134
155
if _ , err := tmpFile .Write ([]byte (rawCmds )); err != nil {
135
156
return nil , err
136
157
}
137
158
159
+ tmpFile .Close ()
160
+
138
161
logrus .Debugf ("WROTE TO FILE:\n %s\n ----\n " , rawCmds )
139
162
140
163
shellParam := sr .parseShellParam (execContext .Shell )
141
164
cmdName , cmdArgs := sr .buildCmdParts (shellParam )
142
- cmdArgs = append (cmdArgs , tmpFile .Name ())
165
+
166
+ if runtime .GOOS == "windows" && execContext .Shell == defaultWindowsShell {
167
+ cmdName = tmpFile .Name ()
168
+ } else {
169
+ cmdArgs = append (cmdArgs , tmpFile .Name ())
170
+ }
143
171
144
172
cmd = exec .Command (cmdName , cmdArgs ... )
145
173
0 commit comments