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:
Keith Rarick
2012-12-03 23:17:35 -08:00
parent 2a896e26c7
commit b07888f6df

View File

@@ -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()
}
```