communicator/winrm: call wg.Add() before running goroutine

This commit is contained in:
Mark Peek 2015-10-14 09:08:39 -07:00
parent e27b2bcf23
commit cad9899cfb
1 changed files with 2 additions and 1 deletions

View File

@ -88,18 +88,19 @@ func runCommand(shell *winrm.Shell, cmd *winrm.Command, rc *packer.RemoteCmd) {
var wg sync.WaitGroup
copyFunc := func(w io.Writer, r io.Reader) {
wg.Add(1)
defer wg.Done()
io.Copy(w, r)
}
if rc.Stdout != nil && cmd.Stdout != nil {
wg.Add(1)
go copyFunc(rc.Stdout, cmd.Stdout)
} else {
log.Printf("[WARN] Failed to read stdout for command '%s'", rc.Command)
}
if rc.Stderr != nil && cmd.Stderr != nil {
wg.Add(1)
go copyFunc(rc.Stderr, cmd.Stderr)
} else {
log.Printf("[WARN] Failed to read stderr for command '%s'", rc.Command)