CommandTTYWithBuffer returns a command with stdin, stdout, and stderr and a buffer that contains stdout and stderr combined.
( name string, arg ...string, )
| 21 | // CommandTTYWithBuffer returns a command with stdin, stdout, and stderr |
| 22 | // and a buffer that contains stdout and stderr combined. |
| 23 | func CommandTTYWithBuffer( |
| 24 | name string, |
| 25 | arg ...string, |
| 26 | ) (*exec.Cmd, *bytes.Buffer) { |
| 27 | cmd := exec.Command(name, arg...) |
| 28 | cmd.Stdin = os.Stdin |
| 29 | |
| 30 | errBuf := bytes.NewBuffer(nil) |
| 31 | outBuf := bytes.NewBuffer(nil) |
| 32 | cmd.Stderr = io.MultiWriter(os.Stderr, errBuf) |
| 33 | cmd.Stdout = io.MultiWriter(os.Stdout, outBuf) |
| 34 | outBuf.Write(errBuf.Bytes()) |
| 35 | return cmd, outBuf |
| 36 | } |
no test coverage detected