Skip to content

Commit

Permalink
Read mktemp output from stdout only, and put stderr output into a sep…
Browse files Browse the repository at this point in the history
…arate stream

fixes #29
  • Loading branch information
Johan Thomsen authored and adamtulinius committed Nov 21, 2018
1 parent 16861df commit c9b07b7
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions ssh/ssh.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ssh

import (
"bytes"
"errors"
"fmt"
"golang.org/x/crypto/ssh/terminal"
Expand Down Expand Up @@ -224,16 +225,21 @@ func (ctx *SSHContext) ActivateConfiguration(host Host, configuration string, ac
func (ctx *SSHContext) MakeTempFile(host Host) (path string, err error) {
cmd, _ := ctx.Cmd(host, "mktemp")

data, err := cmd.CombinedOutput()
var stdout bytes.Buffer
var stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr

err = cmd.Run()
if err != nil {
errorMessage := fmt.Sprintf(
"Error on remote host %s:\nCouldn't create temporary file using mktemp\n\nOriginal error:\n%s",
host.GetTargetHost(), string(data),
host.GetTargetHost(), stderr.String(),
)
return "", errors.New(errorMessage)
}

tempFile := strings.TrimSpace(string(data))
tempFile := strings.TrimSpace(stdout.String())

return tempFile, nil
}
Expand Down

0 comments on commit c9b07b7

Please sign in to comment.