Skip to content

Commit 42aa57e

Browse files
authored
exec: stream command output (#2166)
1 parent 76eb1ea commit 42aa57e

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

providers/dns/exec/exec.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package exec
33

44
import (
5+
"bufio"
56
"context"
67
"errors"
78
"fmt"
@@ -117,10 +118,27 @@ func (d *DNSProvider) run(ctx context.Context, command, domain, token, keyAuth s
117118

118119
cmd := exec.CommandContext(ctx, d.config.Program, args...)
119120

120-
output, err := cmd.CombinedOutput()
121-
if len(output) > 0 {
122-
log.Println(string(output))
121+
stdout, err := cmd.StdoutPipe()
122+
if err != nil {
123+
return fmt.Errorf("create pipe: %w", err)
124+
}
125+
126+
cmd.Stderr = cmd.Stdout
127+
128+
err = cmd.Start()
129+
if err != nil {
130+
return fmt.Errorf("start command: %w", err)
123131
}
124132

125-
return err
133+
scanner := bufio.NewScanner(stdout)
134+
for scanner.Scan() {
135+
log.Println(scanner.Text())
136+
}
137+
138+
err = cmd.Wait()
139+
if err != nil {
140+
return fmt.Errorf("wait command: %w", err)
141+
}
142+
143+
return nil
126144
}

0 commit comments

Comments
 (0)