From 150b7401cf8eb34aec82ab2522ca3ccb9388e15e Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 5 Aug 2025 10:03:26 +0200 Subject: [PATCH] Added RunAndCaptureCombinedOutput --- process.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/process.go b/process.go index 1515f4d..83053a3 100644 --- a/process.go +++ b/process.go @@ -214,6 +214,17 @@ func (p *Process) RunAndCaptureOutput(ctx context.Context) ([]byte, []byte, erro return stdout.Bytes(), stderr.Bytes(), err } +// RunAndCaptureCombinedOutput starts the specified command and waits for it to complete. If the given context +// is canceled before the normal process termination, the process is killed. The standard output and +// standard error of the process are captured and returned combined at process termination. +func (p *Process) RunAndCaptureCombinedOutput(ctx context.Context) ([]byte, error) { + out := &bytes.Buffer{} + p.RedirectStdoutTo(out) + p.RedirectStderrTo(out) + err := p.RunWithinContext(ctx) + return out.Bytes(), err +} + // GetArgs returns the command arguments func (p *Process) GetArgs() []string { return p.cmd.Args