Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid stucking while reading stdout from pty #83

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions reflex.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"bytes"
"errors"
"fmt"
"io"
"os"
"os/exec"
"os/signal"
Expand Down Expand Up @@ -286,14 +287,21 @@ func (r *Reflex) runCommand(name string, stdout chan<- OutMsg) {
chResize <- syscall.SIGWINCH // Initial resize.

go func() {
scanner := bufio.NewScanner(tty)
for scanner.Scan() {
stdout <- OutMsg{r.id, scanner.Text()}
scanner := bufio.NewReader(tty)
for {
buf, _, err := scanner.ReadLine()
if err != nil {
if err == io.EOF {
break
}
// Intentionally ignoring err for now. Unfortunately,
// the pty returns a read error when the child dies naturally,
// so I'm just going to ignore errors here unless I can find a
// better way to handle it.
continue
}
stdout <- OutMsg{r.id, string(buf)}
}
// Intentionally ignoring scanner.Err() for now. Unfortunately,
// the pty returns a read error when the child dies naturally,
// so I'm just going to ignore errors here unless I can find a
// better way to handle it.
}()

r.mu.Lock()
Expand Down