Skip to content

Commit 5df0202

Browse files
committed
Do not alter ctx.Stderr/Stdout in ExecCommand
1 parent efd89c5 commit 5df0202

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

Diff for: legacy/builder/utils/utils.go

+12-11
Original file line numberDiff line numberDiff line change
@@ -184,29 +184,30 @@ const (
184184
)
185185

186186
func ExecCommand(ctx *types.Context, command *exec.Cmd, stdout int, stderr int) ([]byte, []byte, error) {
187-
if ctx.Stdout == nil {
188-
ctx.Stdout = os.Stdout
189-
}
190-
if ctx.Stderr == nil {
191-
ctx.Stderr = os.Stderr
192-
}
193-
194187
if ctx.Verbose {
195188
ctx.Info(PrintableCommand(command.Args))
196189
}
197190

198191
if stdout == Capture {
199192
buffer := &bytes.Buffer{}
200193
command.Stdout = buffer
201-
} else if stdout == Show || stdout == ShowIfVerbose && ctx.Verbose {
202-
command.Stdout = ctx.Stdout
194+
} else if stdout == Show || (stdout == ShowIfVerbose && ctx.Verbose) {
195+
if ctx.Stdout != nil {
196+
command.Stdout = ctx.Stdout
197+
} else {
198+
command.Stdout = os.Stdout
199+
}
203200
}
204201

205202
if stderr == Capture {
206203
buffer := &bytes.Buffer{}
207204
command.Stderr = buffer
208-
} else if stderr == Show || stderr == ShowIfVerbose && ctx.Verbose {
209-
command.Stderr = ctx.Stderr
205+
} else if stderr == Show || (stderr == ShowIfVerbose && ctx.Verbose) {
206+
if ctx.Stderr != nil {
207+
command.Stderr = ctx.Stderr
208+
} else {
209+
command.Stderr = os.Stderr
210+
}
210211
}
211212

212213
err := command.Start()

0 commit comments

Comments
 (0)