See https://play.golang.org/p/ljovw4QPSl. This function executes a command locally and returns both the stdout and stderr. It works most of the time, but sometimes the stdoutbuf.ReadFrom()
call on line 55 returns read |0: bad file descriptor
. I can't figure out what's wrong with the code.
There's nothing guaranteeing your goruoutines are executed before your command program has exited and been collected. If you added a sleep at the start of each goroutine for longer than the life of the command, you would see this error every time.
Wait on the goroutines first, before calling Wait on the command. This will make sure the process is still around for your goroutines to read from.