Skip to content

Commit 92dc364

Browse files
authored
Merge pull request #41 from arduino/combined_output
Added RunAndCaptureCombinedOutput
2 parents b75d2fe + 150b740 commit 92dc364

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

process.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,17 @@ func (p *Process) RunAndCaptureOutput(ctx context.Context) ([]byte, []byte, erro
214214
return stdout.Bytes(), stderr.Bytes(), err
215215
}
216216

217+
// RunAndCaptureCombinedOutput starts the specified command and waits for it to complete. If the given context
218+
// is canceled before the normal process termination, the process is killed. The standard output and
219+
// standard error of the process are captured and returned combined at process termination.
220+
func (p *Process) RunAndCaptureCombinedOutput(ctx context.Context) ([]byte, error) {
221+
out := &bytes.Buffer{}
222+
p.RedirectStdoutTo(out)
223+
p.RedirectStderrTo(out)
224+
err := p.RunWithinContext(ctx)
225+
return out.Bytes(), err
226+
}
227+
217228
// GetArgs returns the command arguments
218229
func (p *Process) GetArgs() []string {
219230
return p.cmd.Args

0 commit comments

Comments
 (0)