Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't close consoleR & consoleW in Windows #7

Merged
merged 2 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ type windowExecCmd struct {
cmd *exec.Cmd
waitCalled bool
conPty *WindowsPty
conTty *WindowsTty
attrList *windows.ProcThreadAttributeListContainer
}

func (c *windowExecCmd) close() error {
c.attrList.Delete()
_ = c.conPty.Close()
_ = c.conTty.Close()

return nil
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/creack/pty/v2

go 1.18
go 1.21.5

require golang.org/x/sys v0.13.0
5 changes: 2 additions & 3 deletions helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import (
"bytes"
"fmt"
"io"
"os"
"testing"
)

// openCloses opens a pty/tty pair and stages the closing as part of the cleanup.
func openClose(t *testing.T) (pty, tty *os.File) {
// openClose opens a pty/tty pair and stages the closing as part of the cleanup.
func openClose(t *testing.T) (Pty, Tty) {
t.Helper()

pty, tty, err := Open()
Expand Down
8 changes: 0 additions & 8 deletions pty_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,6 @@ func open() (_ Pty, _ Tty, err error) {
return nil, nil, err
}

// These pipes can be closed here without any worry.
if err := consoleW.Close(); err != nil {
return nil, nil, fmt.Errorf("failed to close pseudo console write handle: %w", err)
}
if err := consoleR.Close(); err != nil {
return nil, nil, fmt.Errorf("failed to close pseudo console read handle: %w", err)
}

return &WindowsPty{
handle: consoleHandle,
r: pr,
Expand Down
3 changes: 2 additions & 1 deletion run_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func StartWithSize(c *exec.Cmd, sz *Winsize) (Pty, error) {
// This should generally not be needed. Used in some edge cases where it is needed to create a pty
// without a controlling terminal.
func StartWithAttrs(c *exec.Cmd, sz *Winsize, attrs *syscall.SysProcAttr) (Pty, error) {
pty, _, err := open()
pty, tty, err := open()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -62,6 +62,7 @@ func StartWithAttrs(c *exec.Cmd, sz *Winsize, attrs *syscall.SysProcAttr) (Pty,
cmd: c,
waitCalled: false,
conPty: pty.(*WindowsPty),
conTty: tty.(*WindowsTty),
}

if err := w.Start(); err != nil {
Expand Down
Loading