1
0
mirror of https://github.com/go-acme/lego.git synced 2024-11-24 16:53:52 +02:00

exec: stream command output (#2166)

This commit is contained in:
Ludovic Fernandez 2024-04-21 18:01:40 +02:00 committed by GitHub
parent 76eb1eac8a
commit 42aa57e2b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2,6 +2,7 @@
package exec
import (
"bufio"
"context"
"errors"
"fmt"
@ -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)
}
return err
cmd.Stderr = cmd.Stdout
err = cmd.Start()
if err != nil {
return fmt.Errorf("start command: %w", 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
}