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

x/crypto/ssh/terminal: GetSize doesn't work on Windows? #20388

Closed
gbraad opened this issue May 17, 2017 · 4 comments
Closed

x/crypto/ssh/terminal: GetSize doesn't work on Windows? #20388

gbraad opened this issue May 17, 2017 · 4 comments

Comments

@gbraad
Copy link

@gbraad gbraad commented May 17, 2017

What version of Go are you using (go version)?

go1.7.5

What operating system and processor architecture are you using (go env)?

Compared functionality between two platforms:
go on linux/amd64
go on windows/amd64

What did you do?

I am doing the following:

	fd := int(os.Stdin.Fd())

	termWidth, termHeight, err := terminal.GetSize(fd)
	if err != nil {
		return "", err
	}

on Linux, which returns me the correct size of the terminal when using for instance bash. However, this same call will fail on Windows cmd and powershell with an "invalid handle" error.

It seems that "golang.org/x/crypto/ssh/terminal" can not succesfully perform the following function:

func GetSize(fd int) (width, height int, err error)

More information about this can be found at: minishift/minishift-centos-iso#95 (comment) and minishift/minishift-centos-iso#95 (comment). This seems to be an issue when using Red Hat's provided ssh server with the go native implementation: docker/machine#3937

What did you expect to see?

I expected the command to pass

What did you see instead?

At the moment it fails with an invalid handle.

@bradfitz bradfitz changed the title Unable to do getSize of terminal on a Windows host using cmd/powershell targeting CentOS/RHEL x/crypto/ssh/terminal: GetSize doesn't work on Windows? May 17, 2017
@gopherbot gopherbot added this to the Unreleased milestone May 17, 2017
@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented May 17, 2017

I don't understand the bug report.

The Windows code doesn't involve an ioctl. The Windows code is many years old at this point and in util_windows.go:

func GetSize(fd int) (width, height int, err error) {
        var info consoleScreenBufferInfo
        _, _, e := syscall.Syscall(procGetConsoleScreenBufferInfo.Addr(), 2, uintptr(fd), uintptr(unsafe.Pointer(&info)), 0)
        if e != 0 {
                return 0, 0, error(e)
        }
        return int(info.size.x), int(info.size.y), nil
}

What is fd := int(os.Stdin.Fd()) on Windows? Is that valid for GetConsoleScreenBufferInfo?

/cc @alexbrainman

@bradfitz bradfitz added the OS-Windows label May 17, 2017
@gbraad
Copy link
Author

@gbraad gbraad commented May 17, 2017

Will debug util_windows.go. (IDE redirect to the general util.go)

The value I got for the fd was 8 for my PowerShell, and 80 for a cmd instance. Creating a new cmd, returns a different fd (76) for cmd. But all of the calls return "The handle is invalid." as error.

@alexbrainman
Copy link
Member

@alexbrainman alexbrainman commented May 17, 2017

fd := int(os.Stdin.Fd())

Looking at an example https://msdn.microsoft.com/en-us/library/windows/desktop/ms685118(v=vs.85).aspx - the example calls GetStdHandle(STD_OUTPUT_HANDLE) to get the handle. So, I suppose, you should use os.Stdout.Fd() instead.

I am not sure if that is the intended behavior.

Alex

@gbraad
Copy link
Author

@gbraad gbraad commented May 17, 2017

Works as expected with doing:

        fd := int(os.Stdout.Fd())
	termWidth, termHeight, err := terminal.GetSize(fd)

pushing a change to libmachine for this. Cheers

@gbraad gbraad closed this May 17, 2017
@golang golang locked and limited conversation to collaborators May 17, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.