Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion util/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func RunWithRedactor(cmd *exec.Cmd, redactor func(text string) string) (string,
}

func RunWithExecRunOpts(cmd *exec.Cmd, opts ExecRunOpts) (string, error) {
cmdOpts := CmdOpts{Timeout: timeout, FatalTimeout: fatalTimeout, Redactor: opts.Redactor, TimeoutBehavior: opts.TimeoutBehavior, SkipErrorLogging: opts.SkipErrorLogging}
cmdOpts := CmdOpts{Timeout: timeout, FatalTimeout: fatalTimeout, Redactor: opts.Redactor, TimeoutBehavior: opts.TimeoutBehavior, SkipErrorLogging: opts.SkipErrorLogging, CaptureStderr: opts.CaptureStderr}
span := tracing.NewLoggingTracer(log.NewLogrusLogger(log.NewWithCurrentConfig())).StartSpan(fmt.Sprintf("exec %v", cmd.Args[0]))
span.SetBaggageItem("dir", cmd.Dir)
if cmdOpts.Redactor != nil {
Expand Down
8 changes: 8 additions & 0 deletions util/exec/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,11 @@ func TestRunCaptureStderr(t *testing.T) {
assert.Equal(t, "hello world\nmy-error", output)
assert.NoError(t, err)
}

func TestRunWithExecRunOptsCaptureStderr(t *testing.T) {
ctx := t.Context()
cmd := exec.CommandContext(ctx, "sh", "-c", "echo hello world && echo my-error >&2 && exit 0")
output, err := RunWithExecRunOpts(cmd, ExecRunOpts{CaptureStderr: true})
assert.Equal(t, "hello world\nmy-error", output)
assert.NoError(t, err)
}
Loading