Skip to content

Commit a1b859e

Browse files
committed
Add log passthrough for lock-exec
Creates multiwriter with a single buffer (combined output) and std IO file descriptors
1 parent 507ad74 commit a1b859e

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lock/run.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package lock
22

33
import (
4+
"bytes"
45
"context"
56
"fmt"
7+
"io"
8+
"os"
69
"os/exec"
710
"strings"
811
"time"
@@ -20,8 +23,17 @@ func (c *Client) Run(ctx context.Context, key, command string) (string, error) {
2023
return "", fmt.Errorf("lock failed: %w", err)
2124
}
2225

26+
// Build command
2327
fields := strings.Fields(command)
24-
cmdout, cmderr := exec.CommandContext(ctx, fields[0], fields[1:]...).CombinedOutput() //nolint:gosec
28+
cmd := exec.CommandContext(ctx, fields[0], fields[1:]...) //nolint:gosec
29+
30+
// Write to std outputs + combined buffer
31+
var outbuf bytes.Buffer
32+
cmd.Stdout = io.MultiWriter(os.Stdout, &outbuf)
33+
cmd.Stderr = io.MultiWriter(os.Stderr, &outbuf)
34+
35+
cmderr := cmd.Run()
36+
cmdout := outbuf.Bytes()
2537

2638
return strings.TrimSpace(string(cmdout)), cmderr
2739
}

0 commit comments

Comments
 (0)