Fix bad script input buffering strategy

This commit is contained in:
Ethan Marshall 2024-01-24 16:43:13 +00:00
parent a4f579003e
commit f7f231244c
Signed by: ejv2
GPG key ID: EC2FAEF4DB8968D8

View file

@ -1,11 +1,11 @@
package main
import (
"bufio"
"fmt"
"io"
"log"
"os/exec"
"strings"
)
// Pajen represents an instance of the pajen.pl script running in infinite
@ -51,22 +51,17 @@ func (r *Pajen) Read(b []byte) (int, error) {
}
func (r *Pajen) run() {
buf := make([]byte, 255)
sc := bufio.NewScanner(r.out)
sc.Split(bufio.ScanLines)
for {
_, err := r.out.Read(buf)
if err != nil {
log.Println("pajen read error:", err)
return
}
wk := string(buf)
lines := strings.Split(wk, "\n")
for _, l := range lines {
for sc.Scan() {
l := sc.Text()
if l != "" && l != "\n" {
r.Chan <- l
}
}
if sc.Err() != nil {
log.Println("pajen: output read error: %s", sc.Err())
}
}