Skip to content

Commit 66533f7

Browse files
committed
Add CombinedOutput
With the fix to Stdout/Stderr handling, we can now implement CombinedOutput() Signed-off-by: Ronald G Minnich <rminnich@gmail.com>
1 parent 7fb3c0f commit 66533f7

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

client/client.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,21 @@ func (c *Cmd) Run() error {
569569
return c.Wait()
570570
}
571571

572+
func (c *Cmd) CombinedOutput() ([]byte, error) {
573+
r, w, err := os.Pipe()
574+
if err != nil {
575+
return nil, err
576+
}
577+
578+
c.Stdout, c.Stderr = w, w
579+
580+
cpuerr := c.Run()
581+
582+
b, err := io.ReadAll(r)
583+
584+
return b, errors.Join(cpuerr, err)
585+
}
586+
572587
// TTYIn manages tty input for a cpu session.
573588
// It exists mainly to deal with ~.
574589
func (c *Cmd) TTYIn(s *ssh.Session, w io.WriteCloser, r io.Reader) {

0 commit comments

Comments
 (0)