diff --git a/builder/parallels/common/step_shutdown.go b/builder/parallels/common/step_shutdown.go index e3ce2b1c2..3a93c1767 100644 --- a/builder/parallels/common/step_shutdown.go +++ b/builder/parallels/common/step_shutdown.go @@ -1,6 +1,7 @@ package common import ( + "bytes" "errors" "fmt" "log" @@ -36,9 +37,15 @@ func (s *StepShutdown) Run(state multistep.StateBag) multistep.StepAction { if s.Command != "" { ui.Say("Gracefully halting virtual machine...") log.Printf("Executing shutdown command: %s", s.Command) - cmd := &packer.RemoteCmd{Command: s.Command} - if err := cmd.StartWithUi(comm, ui); err != nil { - err = fmt.Errorf("Failed to send shutdown command: %s", err) + + var stdout, stderr bytes.Buffer + cmd := &packer.RemoteCmd{ + Command: s.Command, + Stdout: &stdout, + Stderr: &stderr, + } + if err := comm.Start(cmd); err != nil { + err := fmt.Errorf("Failed to send shutdown command: %s", err) state.Put("error", err) ui.Error(err.Error()) return multistep.ActionHalt @@ -55,6 +62,8 @@ func (s *StepShutdown) Run(state multistep.StateBag) multistep.StepAction { select { case <-shutdownTimer: + log.Printf("Shutdown stdout: %s", stdout.String()) + log.Printf("Shutdown stderr: %s", stderr.String()) err := errors.New("Timeout while waiting for machine to shut down.") state.Put("error", err) ui.Error(err.Error()) diff --git a/builder/vmware/common/step_shutdown.go b/builder/vmware/common/step_shutdown.go index 666649993..8fcef7496 100644 --- a/builder/vmware/common/step_shutdown.go +++ b/builder/vmware/common/step_shutdown.go @@ -57,14 +57,6 @@ func (s *StepShutdown) Run(state multistep.StateBag) multistep.StepAction { return multistep.ActionHalt } - // Wait for the command to run so we can print std{err,out} - // We don't care if the command errored, since we'll notice - // if the vm didn't shut down. - cmd.Wait() - - log.Printf("Shutdown stdout: %s", stdout.String()) - log.Printf("Shutdown stderr: %s", stderr.String()) - // Wait for the machine to actually shut down log.Printf("Waiting max %s for shutdown to complete", s.Timeout) shutdownTimer := time.After(s.Timeout) @@ -76,6 +68,8 @@ func (s *StepShutdown) Run(state multistep.StateBag) multistep.StepAction { select { case <-shutdownTimer: + log.Printf("Shutdown stdout: %s", stdout.String()) + log.Printf("Shutdown stderr: %s", stderr.String()) err := errors.New("Timeout while waiting for machine to shut down.") state.Put("error", err) ui.Error(err.Error()) diff --git a/packer/communicator.go b/packer/communicator.go index 83a4a60de..ad6a9a5bd 100644 --- a/packer/communicator.go +++ b/packer/communicator.go @@ -9,7 +9,7 @@ import ( "github.com/mitchellh/iochan" ) -// CmdDisconnect is a sentry value to indicate a RemoteCmd +// CmdDisconnect is a sentinel value to indicate a RemoteCmd // exited because the remote side disconnected us. const CmdDisconnect int = 2300218