Commit 641c4645 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer: Preserve original stdout/stderr on StartWithUi

/cc @sit
parent 665b03a3
......@@ -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 {
......
......@@ -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) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment