diff --git a/packer/communicator.go b/packer/communicator.go index a959d79c6..b16e2d348 100644 --- a/packer/communicator.go +++ b/packer/communicator.go @@ -67,8 +67,17 @@ func (r *RemoteCmd) StartWithUi(c Communicator, ui Ui) error { stderr_r, stderr_w := io.Pipe() // Set the writers for the output so that we get it streamed to us - r.Stdout = stdout_w - r.Stderr = stderr_w + if r.Stdout == nil { + r.Stdout = stdout_w + } else { + r.Stdout = io.MultiWriter(r.Stdout, stdout_w) + } + + if r.Stderr == nil { + r.Stderr = stderr_w + } else { + r.Stderr = io.MultiWriter(r.Stderr, stderr_w) + } // Start the command if err := c.Start(r); err != nil { diff --git a/packer/communicator_test.go b/packer/communicator_test.go index 484b508e9..96e823a26 100644 --- a/packer/communicator_test.go +++ b/packer/communicator_test.go @@ -38,6 +38,7 @@ func (c *TestCommunicator) Download(string, io.Writer) error { func TestRemoteCmd_StartWithUi(t *testing.T) { data := "hello\nworld\nthere" + originalOutput := new(bytes.Buffer) rcOutput := new(bytes.Buffer) uiOutput := new(bytes.Buffer) rcOutput.WriteString(data) @@ -53,6 +54,7 @@ func TestRemoteCmd_StartWithUi(t *testing.T) { rc := &RemoteCmd{ Command: "test", + Stdout: originalOutput, } go func() { @@ -68,6 +70,10 @@ func TestRemoteCmd_StartWithUi(t *testing.T) { if uiOutput.String() != strings.TrimSpace(data)+"\n" { t.Fatalf("bad output: '%s'", uiOutput.String()) } + + if originalOutput.String() != data { + t.Fatalf("original is bad: '%s'", originalOutput.String()) + } } func TestRemoteCmd_Wait(t *testing.T) {