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.
diff --git a/README.md b/README.md
index dc9e7c3..85c7c4e 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,6 @@
package main
import (
- "fmt"
"github.com/kr/pty"
"io"
"os"
@@ -30,12 +29,11 @@
}
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()
}
```