Skip to content

Commit

Permalink
Merge pull request #15 from cockroachdb/combinedoutput
Browse files Browse the repository at this point in the history
don't call into `CombinedOutput` for subprocesses
  • Loading branch information
rickystewart authored Mar 10, 2022
2 parents 94cf65c + d14e8fa commit 58fb462
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,33 @@ func run() error {
}).Stop()
}
}
combinedOutput, err := ioutil.TempFile("", "stress-stdouterr")
if err != nil {
panic(err)
}
defer func() { _ = os.Remove(combinedOutput.Name()) }()
cmd = exec.CommandContext(ctx, flags.Args()[0], flags.Args()[1:]...)
cmd.Env = subenviron
out, err := cmd.CombinedOutput()
result.output = out
if err != nil && (failureRe == nil || failureRe.Match(out)) && (ignoreRe == nil || !ignoreRe.Match(out)) {
result.output = append(out, fmt.Sprintf("\n\nERROR: %v\n", err)...)
cmd.Stdout = combinedOutput
cmd.Stderr = combinedOutput
cmdErr := cmd.Run()
_, err = combinedOutput.Seek(0, 0)
if err != nil {
result.output = []byte("stress: could not seek to beginning of stdout/stderr for test")
} else {
out, err := ioutil.ReadAll(combinedOutput)
if err != nil {
result.output = []byte("stress: could not read stdout/stderr for test")
} else {
result.output = out
}
}
err = combinedOutput.Close()
if err != nil {
panic(err)
}
if cmdErr != nil && (failureRe == nil || failureRe.Match(result.output)) && (ignoreRe == nil || !ignoreRe.Match(result.output)) {
result.output = append(result.output, fmt.Sprintf("\n\nERROR: %v\n", err)...)
} else {
result.success = true
}
Expand Down

0 comments on commit 58fb462

Please sign in to comment.