Skip to content

Commit

Permalink
Merge pull request #7 from HuckRidgeSW/master
Browse files Browse the repository at this point in the history
Don't close consoleR & consoleW in Windows
  • Loading branch information
photostorm authored Apr 14, 2024
2 parents 17650f9 + bf40468 commit 871f917
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 13 deletions.
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

0 comments on commit 871f917

Please sign in to comment.