Fix bad script input buffering strategy
This commit is contained in:
parent
a4f579003e
commit
f7f231244c
1 changed files with 11 additions and 16 deletions
21
pajen.go
21
pajen.go
|
@ -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())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue