From b07888f6df6ec126c120fdf6b20bb440db03c589 Mon Sep 17 00:00:00 2001 From: Keith Rarick Date: Mon, 3 Dec 2012 23:17:35 -0800 Subject: [PATCH] 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. --- README.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index dc9e7c3..85c7c4e 100644 --- a/README.md +++ b/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() } ```