commit | 95d05c1eef33a45bd58676b6ce28d105839b8d0b | [log] [tgz] |
---|---|---|
author | Guillaume J. Charmes <guillaume@charmes.net> | Fri Oct 06 13:48:01 2017 -0400 |
committer | GitHub <noreply@github.com> | Fri Oct 06 13:48:01 2017 -0400 |
tree | 320320225a749c8246443de1ce42f27e1ed24210 | |
parent | 2c10821df3c3cf905230d078702dfbe9404c9b23 [diff] |
Prevent golang to set the non-block flag on ptmx open to avoid 100% CPU usage on reads (#53) Signed-off-by: Guillaume J. Charmes <guillaume@charmes.net>
Pty is a Go package for using unix pseudo-terminals.
go get github.com/kr/pty
package main import ( "github.com/kr/pty" "io" "os" "os/exec" ) func main() { c := exec.Command("grep", "--color=auto", "bar") f, err := pty.Start(c) if err != nil { panic(err) } go func() { f.Write([]byte("foo\n")) f.Write([]byte("bar\n")) f.Write([]byte("baz\n")) f.Write([]byte{4}) // EOT }() io.Copy(os.Stdout, f) }