go
go copied to clipboard
x/crypto/ssh/terminal: terminal.ReadPassword doesn't work when using Bash for Windows (from Git installation)
What version of Go are you using (go version
)?
$ go version go version go1.12.5 windows/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env set GOARCH=amd64 set GOBIN= set GOCACHE=C:\Users\mrausc\AppData\Local\go-build set GOEXE=.exe set GOFLAGS= set GOHOSTARCH=amd64 set GOHOSTOS=windows set GOOS=windows set GOPATH=C:\Users\mrausc\go set GOPROXY= set GORACE= set GOROOT=C:\MyProgs\Go set GOTMPDIR= set GOTOOLDIR=C:\MyProgs\Go\pkg\tool\windows_amd64 set GCCGO=gccgo set CC=gcc set CXX=g++ set CGO_ENABLED=1 set GOMOD=X:\swda\play\go.mod set CGO_CFLAGS=-g -O2 set CGO_CPPFLAGS= set CGO_CXXFLAGS=-g -O2 set CGO_FFLAGS=-g -O2 set CGO_LDFLAGS=-g -O2 set PKG_CONFIG=pkg-config set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\mrausc\AppData\Local\Temp\go-build325358090=/tmp/go-build -gno-record-gcc-switches
What did you do?
func main() { _, err := terminal.ReadPassword(int(os.Stdin.Fd())) fmt.Println(err) }
What did you expect to see?
no echo of password
What did you see instead?
"The handle is invalid."
CC @hanwen @FiloSottile
I got the same issue.
Do you use third-party terminal application? If you use mintty, an application which use Windows Console APIs does not work. you must use winpty to run the application.
We are facing the same issue but found out something slightly odd. First, we use the new golang.org/x/term
package rather than x/crypto/ssh/terminal
as mentioned in the title of this issue.
We face the same issue as described in this issue in Git Bash. The code is here: https://github.com/Scalingo/cli/blob/master/term/password.go#L13
But if we run Git Bash from within the terminal tab of VS Code, we no longer face the same issue, everything works as expected.
Does anyone know what is the difference between Git Bash and Git Bash inside VS Code?
I can't reproduce this. Windows 11 21H2 64Bit amd64.
I uploaded the smallest example which reproduces the issue here: https://github.com/EtienneM/mwe_read_password/blob/master/main.go
I'm not exactly sure about what information may be needed. My OS version:
C:\Users\Administrator>systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
OS Name: Microsoft Windows Server 2019 Datacenter
OS Version: 10.0.17763 N/A Build 17763
The Go version:
C:\Users\Administrator>go version
go version go1.19.2 windows/amd64
The golang.org/x/term
version is:
$ cat go.mod | grep "golang.org/x/term"
require golang.org/x/term v0.0.0-20220919170432-7a66f970e087
With this example, in Git Bash in VS Code I can type a password and the output is:
$ go build && ./mwe.exe
<nil>
In Git Bash outside of VS Code, I can't type the password and immediately get the error:
$ go build && ./mwe.exe
The handle is invalid.
I hit this problem as well. Run on mingw64 shell - If I run on windows cmd then it works. It is both on window 8 and windows 10 at my work place.