mirror of
https://github.com/creack/pty.git
synced 2026-04-01 02:57:06 +09:00
fix race in sample code
Don't close the pty directly; instead send an EOT to cause the terminal to indicate end-of-file in the slave device. Closing the pty caused io.Copy to return early. Fixes #7.
This commit is contained in:
10
README.md
10
README.md
@@ -15,7 +15,6 @@ for other systems!)
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/kr/pty"
|
||||
"io"
|
||||
"os"
|
||||
@@ -30,12 +29,11 @@ func main() {
|
||||
}
|
||||
|
||||
go func() {
|
||||
fmt.Fprintln(f, "foo")
|
||||
fmt.Fprintln(f, "bar")
|
||||
fmt.Fprintln(f, "baz")
|
||||
f.Close()
|
||||
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)
|
||||
c.Wait()
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user