diff --git a/communicator/winrm/communicator.go b/communicator/winrm/communicator.go index 27ba31a83..30998e0b1 100644 --- a/communicator/winrm/communicator.go +++ b/communicator/winrm/communicator.go @@ -7,6 +7,7 @@ import ( "math/rand" "strconv" "strings" + "sync" "time" "github.com/hashicorp/terraform/communicator/remote" @@ -148,10 +149,20 @@ func (c *Communicator) Start(rc *remote.Cmd) error { func runCommand(shell *winrm.Shell, cmd *winrm.Command, rc *remote.Cmd) { defer shell.Close() - go io.Copy(rc.Stdout, cmd.Stdout) - go io.Copy(rc.Stderr, cmd.Stderr) + var wg sync.WaitGroup + go func() { + wg.Add(1) + io.Copy(rc.Stdout, cmd.Stdout) + wg.Done() + }() + go func() { + wg.Add(1) + io.Copy(rc.Stderr, cmd.Stderr) + wg.Done() + }() cmd.Wait() + wg.Wait() rc.SetExited(cmd.ExitCode()) }