From 0e53a26d6fd1674f86f9ca3352544eee2f1f3326 Mon Sep 17 00:00:00 2001 From: mjarkk Date: Thu, 1 Nov 2018 07:06:34 +0100 Subject: [PATCH] Maybe fixed the test this time --- pkg/commands/exec_live_default.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/pkg/commands/exec_live_default.go b/pkg/commands/exec_live_default.go index 69cb7dec0..99ad698b5 100644 --- a/pkg/commands/exec_live_default.go +++ b/pkg/commands/exec_live_default.go @@ -8,6 +8,7 @@ import ( "os/exec" "regexp" "strings" + "sync" "github.com/kr/pty" ) @@ -19,7 +20,6 @@ import ( // NOTE: You don't have to include a enter in the return data this function will do that for you func RunCommandWithOutputLiveWrapper(c *OSCommand, command string, output func(string) string) (errorMessage string, codeError error) { cmdOutput := []string{} - isAlreadyClosed := false splitCmd := ToArgv(command) cmd := exec.Command(splitCmd[0], splitCmd[1:]...) @@ -33,11 +33,11 @@ func RunCommandWithOutputLiveWrapper(c *OSCommand, command string, output func(s return errorMessage, err } + var waitForBufio sync.WaitGroup + waitForBufio.Add(1) + defer func() { - if !isAlreadyClosed { - isAlreadyClosed = true - _ = tty.Close() - } + _ = tty.Close() }() go func() { @@ -55,13 +55,11 @@ func RunCommandWithOutputLiveWrapper(c *OSCommand, command string, output func(s _, _ = tty.Write([]byte(toWrite + "\n")) } } + waitForBufio.Done() }() if err := cmd.Wait(); err != nil { - if !isAlreadyClosed { - isAlreadyClosed = true - _ = tty.Close() - } + waitForBufio.Wait() return strings.Join(cmdOutput, " "), err }