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