From 0a71ca4f0f8cbd4bbf38919907c896e5209adbb8 Mon Sep 17 00:00:00 2001 From: photostorm Date: Tue, 25 Oct 2022 21:23:44 -0400 Subject: [PATCH] cleanup some unused fields --- cmd_windows.go | 12 +++++------- pty_windows.go | 8 -------- run_windows.go | 16 ++++++---------- 3 files changed, 11 insertions(+), 25 deletions(-) diff --git a/cmd_windows.go b/cmd_windows.go index fc30d2f..d36924f 100644 --- a/cmd_windows.go +++ b/cmd_windows.go @@ -28,12 +28,10 @@ import ( // A cmd cannot be reused after calling its Run, Output or CombinedOutput // methods. type windowExecCmd struct { - cmd *exec.Cmd - waitCalled bool - consoleHandle syscall.Handle - tty *WindowsTty - conPty *WindowsPty - attrList *windows.ProcThreadAttributeListContainer + cmd *exec.Cmd + waitCalled bool + conPty *WindowsPty + attrList *windows.ProcThreadAttributeListContainer } var errProcessNotStarted = errors.New("exec: process has not started yet") @@ -41,7 +39,7 @@ var errProcessNotStarted = errors.New("exec: process has not started yet") func (c *windowExecCmd) close() error { c.attrList.Delete() _ = c.conPty.Close() - _ = c.tty.Close() + return nil } diff --git a/pty_windows.go b/pty_windows.go index 04fda46..aa8eb0b 100644 --- a/pty_windows.go +++ b/pty_windows.go @@ -109,14 +109,6 @@ func (p *WindowsPty) WriteString(s string) (int, error) { return p.w.WriteString(s) } -func (p *WindowsPty) InputPipe() *os.File { - return p.w -} - -func (p *WindowsPty) OutputPipe() *os.File { - return p.r -} - func (p *WindowsPty) UpdateProcThreadAttribute(attrList *windows.ProcThreadAttributeListContainer) error { var err error diff --git a/run_windows.go b/run_windows.go index a22f258..37474fb 100644 --- a/run_windows.go +++ b/run_windows.go @@ -33,8 +33,8 @@ 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, err error) { - pty, tty, err := open() +func StartWithAttrs(c *exec.Cmd, sz *Winsize, attrs *syscall.SysProcAttr) (Pty, error) { + pty, _, err := open() if err != nil { return nil, err } @@ -42,7 +42,6 @@ func StartWithAttrs(c *exec.Cmd, sz *Winsize, attrs *syscall.SysProcAttr) (_ Pty defer func() { // unlike unix command exec, do not close tty unless error happened if err != nil { - _ = tty.Close() _ = pty.Close() } }() @@ -60,16 +59,13 @@ func StartWithAttrs(c *exec.Cmd, sz *Winsize, attrs *syscall.SysProcAttr) (_ Pty // do not use os/exec.Start since we need to append console handler to startup info w := windowExecCmd{ - cmd: c, - waitCalled: false, - consoleHandle: syscall.Handle(tty.Fd()), - tty: tty.(*WindowsTty), - conPty: pty.(*WindowsPty), + cmd: c, + waitCalled: false, + conPty: pty.(*WindowsPty), } err = w.Start() if err != nil { - _ = tty.Close() _ = pty.Close() return nil, err } @@ -176,7 +172,7 @@ func (c *windowExecCmd) Start() error { // Need EXTENDED_STARTUPINFO_PRESENT as we're making use of the attribute list field. flags := sys.CreationFlags | uint32(windows.CREATE_UNICODE_ENVIRONMENT) | windows.EXTENDED_STARTUPINFO_PRESENT - c.attrList, err = windows.NewProcThreadAttributeList(3) + c.attrList, err = windows.NewProcThreadAttributeList(1) if err != nil { return fmt.Errorf("failed to initialize process thread attribute list: %w", err) }