|
1 | 1 | package main |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "bufio" |
5 | | - "bytes" |
6 | 4 | "context" |
7 | | - "io" |
8 | 5 | "io/ioutil" |
9 | 6 | "log" |
10 | 7 | "net/http" |
@@ -155,61 +152,11 @@ func (env *environment) getPlatform() string { |
155 | 152 | } |
156 | 153 |
|
157 | 154 | func (env *environment) runCommand(command string, args ...string) (string, error) { |
158 | | - getOutputString := func(io io.ReadCloser) string { |
159 | | - output := new(bytes.Buffer) |
160 | | - defer output.Reset() |
161 | | - buf := bufio.NewReader(io) |
162 | | - multiline := false |
163 | | - for { |
164 | | - line, _, _ := buf.ReadLine() |
165 | | - if line == nil { |
166 | | - break |
167 | | - } |
168 | | - if multiline { |
169 | | - output.WriteString("\n") |
170 | | - } |
171 | | - output.Write(line) |
172 | | - multiline = true |
173 | | - } |
174 | | - return output.String() |
175 | | - } |
176 | | - cmd := exec.Command(command, args...) |
177 | | - stdout, err := cmd.StdoutPipe() |
178 | | - if err != nil { |
179 | | - return "", &commandError{ |
180 | | - err: err.Error(), |
181 | | - exitCode: 666, |
182 | | - } |
183 | | - } |
184 | | - stderr, err := cmd.StderrPipe() |
185 | | - if err != nil { |
186 | | - return "", &commandError{ |
187 | | - err: err.Error(), |
188 | | - exitCode: 667, |
189 | | - } |
190 | | - } |
191 | | - err = cmd.Start() |
| 155 | + out, err := exec.Command(command, args...).Output() |
192 | 156 | if err != nil { |
193 | | - return "", &commandError{ |
194 | | - err: err.Error(), |
195 | | - exitCode: 668, |
196 | | - } |
197 | | - } |
198 | | - defer func() { |
199 | | - _ = cmd.Process.Kill() |
200 | | - }() |
201 | | - stdoutString := getOutputString(stdout) |
202 | | - stderrString := getOutputString(stderr) |
203 | | - if stderrString != "" { |
204 | | - // only wait in case of error reduces the lead time on successful |
205 | | - // commands on windows due to not calling process.Wait() |
206 | | - _ = cmd.Wait() |
207 | | - return "", &commandError{ |
208 | | - err: stderrString, |
209 | | - exitCode: cmd.ProcessState.ExitCode(), |
210 | | - } |
| 157 | + return "", err |
211 | 158 | } |
212 | | - return stdoutString, nil |
| 159 | + return strings.TrimSpace(string(out)), nil |
213 | 160 | } |
214 | 161 |
|
215 | 162 | func (env *environment) runShellCommand(shell, command string) string { |
|
0 commit comments