Fix bad script input buffering strategy
This commit is contained in:
parent
a4f579003e
commit
f7f231244c
1 changed files with 11 additions and 16 deletions
27
pajen.go
27
pajen.go
|
@ -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 {
|
||||
if l != "" && l != "\n" {
|
||||
r.Chan <- l
|
||||
}
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue