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:
parent
76eb1eac8a
commit
42aa57e2b9
@ -2,6 +2,7 @@
|
|||||||
package exec
|
package exec
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"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...)
|
cmd := exec.CommandContext(ctx, d.config.Program, args...)
|
||||||
|
|
||||||
output, err := cmd.CombinedOutput()
|
stdout, err := cmd.StdoutPipe()
|
||||||
if len(output) > 0 {
|
if err != nil {
|
||||||
log.Println(string(output))
|
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
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user