Skip to content

Commit

Permalink
exec: stream command output (#2166)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez authored Apr 21, 2024
1 parent 76eb1ea commit 42aa57e
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions providers/dns/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package exec

import (
"bufio"
"context"
"errors"
"fmt"
Expand Down Expand Up @@ -117,10 +118,27 @@ func (d *DNSProvider) run(ctx context.Context, command, domain, token, keyAuth s

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

output, err := cmd.CombinedOutput()
if len(output) > 0 {
log.Println(string(output))
stdout, err := cmd.StdoutPipe()
if err != nil {
return fmt.Errorf("create pipe: %w", err)
}

cmd.Stderr = cmd.Stdout

err = cmd.Start()
if err != nil {
return fmt.Errorf("start command: %w", err)
}

return err
scanner := bufio.NewScanner(stdout)
for scanner.Scan() {
log.Println(scanner.Text())
}

err = cmd.Wait()
if err != nil {
return fmt.Errorf("wait command: %w", err)
}

return nil
}

0 comments on commit 42aa57e

Please sign in to comment.