Merge pull request #626 from zeeZ/bugfix/wait-for-cmd-reads

Wait for cmd reads to complete before calling Wait()
pull/655/head
Hunter Long 2020-06-10 10:58:59 -07:00 committed by GitHub
commit e3c8b9b2ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 3 deletions

View File

@ -13,6 +13,7 @@ import (
"os/exec"
"strconv"
"strings"
"sync"
"time"
"github.com/ararog/timeago"
@ -114,14 +115,18 @@ func Command(name string, args ...string) (string, string, error) {
return "", "", err
}
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
stdout, errStdout = copyAndCapture(os.Stdout, stdoutIn)
}()
go func() {
stderr, errStderr = copyAndCapture(os.Stderr, stderrIn)
}()
stderr, errStderr = copyAndCapture(os.Stderr, stderrIn)
// call testCmd.Wait() only after reads from all pipes have completed
wg.Wait()
err = testCmd.Wait()
if err != nil {
return string(stdout), string(stderr), err