Skip to content

Start/Wait on exec.Cmd when using pipes

Warren Gifford requested to merge mrn/correctly-pipe-output into main

Created by: mrnugget

This might've been the cause for the flaky test we saw (example failure here).

The docs say that cmd.Run() in combination with StdoutPipe/StderrPipe is wrong:

Wait will close the pipe after seeing the command exit, so most callers need not close the pipe themselves. It is thus incorrect to call Wait before all reads from the pipe have completed. For the same reason, it is incorrect to call Run when using StdoutPipe. See the example for idiomatic usage.

See: https://pkg.go.dev/os/exec#example-Cmd.StdoutPipe

Merge request reports

Loading