From 8a792099a545eef2737fe68416cb995ccc046062 Mon Sep 17 00:00:00 2001 From: Saxon Nelson-Milton Date: Thu, 21 Jan 2021 13:14:45 +1030 Subject: [PATCH] device/raspistill/imp_release.go: improve error checking routine and removed unused const --- device/raspistill/imp_release.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/device/raspistill/imp_release.go b/device/raspistill/imp_release.go index bc6e3dc5..72af63b9 100644 --- a/device/raspistill/imp_release.go +++ b/device/raspistill/imp_release.go @@ -33,7 +33,7 @@ import ( "errors" "fmt" "io" - "io/ioutil" + "bufio" "os/exec" "strings" @@ -73,7 +73,6 @@ func (r *Raspistill) stop() error { } func (r *Raspistill) start() error { - const disabled = "0" args := []string{ "--output", "-", "--nopreview", @@ -99,23 +98,25 @@ func (r *Raspistill) start() error { return fmt.Errorf("could not pipe command error: %w", err) } + go func() { + errScnr := bufio.NewScanner(stderr) for { select { case <-r.done: r.log.Info("raspistill.Stop() called, finished checking stderr") return default: - buf, err := ioutil.ReadAll(stderr) - if err != nil { - r.log.Error("could not read stderr", "error", err) - return - } + } - if len(buf) != 0 { - r.log.Error("error from raspistill stderr", "error", string(buf)) - return - } + if errScnr.Scan() { + r.log.Error("error line from raspistill stderr","error",errScnr.Text()) + continue + } + + err := errScnr.Err() + if err != nil { + r.log.Error("error from stderr scan","error",err) } } }()