-
-
Notifications
You must be signed in to change notification settings - Fork 258
Closed
Description
After ptmx is closed, io.Copy will not read and return an error.
example:
package main
import (
"os/exec"
"io"
"fmt"
"time"
"github.com/creack/pty"
)
type w struct{}
func main() {
cmd := exec.Command("bash")
ptmx, err := pty.Start(cmd)
if err != nil {
panic(err)
}
go func() {
time.Sleep(1* time.Second)
fmt.Println("timeout")
ptmx.Close()
}()
fmt.Println(io.Copy(&w{}, ptmx))
fmt.Println("stop")
}
func (*w) Write(p []byte) (int,error) {
return len(p), nil
}
example2:
func main() {
cmd := exec.Command("bash")
ptmx, err := pty.Start(cmd)
if err != nil {
panic(err)
}
go func() {
time.Sleep(1 * time.Second)
fmt.Println("timeout")
ptmx.Close()
}()
body := make([]byte, 2048)
for {
n, err := ptmx.Read(body)
if err != nil {
fmt.Println(err)
break
}
fmt.Println(body[0:n], err)
}
fmt.Println("stop")
}
Metadata
Metadata
Assignees
Labels
No labels