On Sat, May 16, 2020 at 4:27 AM 'Michael Stiller' via golang-nuts
<[email protected]> wrote:
>
> i try to read tailed lines of a logfile using this approach:
>
> if env.TailEnabled {
>    log.Println("setup tail command")
>    cmd := exec.Command("/usr/bin/tail", "-F", "logfile.log")
>    log.Println("setup tail pipe")
>    tailPipe, err := cmd.StdoutPipe()
>    if err != nil {
>       log.Fatalln("could not open stdin pipe from tail:", err)
>    }
>    log.Println("starting tail pipe scanner")
>
>    scanner = bufio.NewScanner(tailPipe)
>
>    go func() {
>       log.Println("starting tail command")
>       err = cmd.Start()
>
>       if err != nil {
>          log.Fatalln("could not start tail:", err)
>       }
>       log.Println("tail pid:", cmd.Process.Pid)
>       log.Println("waiting for tail to exit")
>       err = cmd.Wait()
>    }()
> }
> log.Println("starting scanner")
> for scanner.Scan() {
>    data := scanner.Bytes()
>    …
> }
>
> Output:
>
> 2020/05/16 11:21:11 setup tail command
> 2020/05/16 11:21:11 setup tail pipe
> 2020/05/16 11:21:11 starting tail pipe scanner
> 2020/05/16 11:21:11 rate limiter: &{limit:3000 burst:100 mu:{state:0 sema:0} 
> tokens:0 last:{wall:0 ext:0 loc:<nil>} lastEvent:{wall:0 ext:0 loc:<nil>}}
> 2020/05/16 11:21:11 starting scanner
> 2020/05/16 11:21:11 starting tail command
> 2020/05/16 11:21:11 tail pid: 30823
> 2020/05/16 11:21:11 waiting for tail to exit
> … nothing more
>
> tail is from coreutils 8.25-2ubuntu3~16.04, kernel 4.4.0-1083-aws
>
> It looks like i cannot read lines that way and tail is blocking in write(1, 
> ...

Running "tail -F" never terminates.  That's how it works.  Your call
to Wait will never complete.

I don't understand what else is going wrong.  Sorry if I missed it.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcUAJsxvxFUKMrK2sxytQHcwBU3tb9EgypZdW1rcK2%3DWuw%40mail.gmail.com.

Reply via email to