diff --git a/communicator/winrm/communicator.go b/communicator/winrm/communicator.go index d90cd8450..59034fcf0 100644 --- a/communicator/winrm/communicator.go +++ b/communicator/winrm/communicator.go @@ -85,8 +85,17 @@ func (c *Communicator) Start(rc *packer.RemoteCmd) error { func runCommand(shell *winrm.Shell, cmd *winrm.Command, rc *packer.RemoteCmd) { defer shell.Close() - go io.Copy(rc.Stdout, cmd.Stdout) - go io.Copy(rc.Stderr, cmd.Stderr) + if rc.Stdout != nil && cmd.Stdout != nil { + go io.Copy(rc.Stdout, cmd.Stdout) + } else { + log.Printf("[WARN] Failed to read stdout for command '%s'", rc.Command) + } + + if rc.Stderr != nil && cmd.Stderr != nil { + go io.Copy(rc.Stderr, cmd.Stderr) + } else { + log.Printf("[WARN] Failed to read stderr for command '%s'", rc.Command) + } cmd.Wait()