Skip to content

Commit 15bfe27

Browse files
0x2b3bfa0restyled-io[bot]restyled-commits
committed
Use CombinedOutput for capturing SSH output (#108)
* Use CombinedOutput for capturing SSH output Fixes a buffer writing bug where the function would return an empty string after a succesful read * Restyled by gofmt (#109) Co-authored-by: Restyled.io <commits@restyled.io> Co-authored-by: restyled-io[bot] <32688539+restyled-io[bot]@users.noreply.github.com> Co-authored-by: Restyled.io <commits@restyled.io>
1 parent ae6b815 commit 15bfe27

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

iterative/utils/ssh.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package utils
22

33
import (
4-
"bytes"
54
"crypto/rand"
65
"crypto/rsa"
76
"crypto/x509"
@@ -72,10 +71,10 @@ func RunCommand(command string, timeout time.Duration, hostAddress string, userN
7271
}
7372
defer session.Close()
7473

75-
var buffer bytes.Buffer
76-
session.Stdout = &buffer
77-
session.Stderr = &buffer
74+
output, err := session.CombinedOutput(command)
75+
if err != nil {
76+
return "", err
77+
}
7878

79-
err = session.Run(command)
80-
return buffer.String(), err
79+
return string(output), nil
8180
}

0 commit comments

Comments
 (0)