msys2.github.io
msys2.github.io copied to clipboard
mintty.exe is a strange terminal
It would be really nice if somebody could look at the following issue: https://github.com/golang/go/issues/46681
It demonstrates the fact that git-bash.exe
and also mingw.exe
really behave strange, when we want to the get the controlling terminal file input CONIN$
on windows.
This is basically done in GO with:
package main
import (
"bufio"
"fmt"
"io"
"os"
"syscall"
"golang.org/x/term"
)
func GetCttyIn() (io.Reader, error) {
in, err := syscall.Open("CONIN$", syscall.O_RDWR, 0)
if err != nil {
return nil, err
}
fmt.Println("$CONIN Isterm: ", isatty.IsTerminal(uintptr(in)))
return os.NewFile(uintptr(in), "/dev/tty"), nil
}
func main() {
fmt.Println("In: ", term.IsTerminal(int(os.Stdin.Fd())))
fmt.Println("Out: ", term.IsTerminal(int(os.Stdout.Fd())))
in, err := GetCttyIn()
if err != nil {
panic(err)
}
scanner := bufio.NewScanner(in)
success := scanner.Scan()
if !success {
panic(err)
}
fmt.Println("Res:", scanner.Text())
}
Running the above with echo "asd" | go run main.go
in vs code integrate terminal with bash.exe
(MSYS2) **works **(suprisingly) but
running it in the git-bash.exe
or msyswin64.exe
(mintty.exe
) does not work:
VS Code: (bash.exe)
In: false
Out: true
$CONIN Isterm: true
asd
Res: asd
Correct!
Straight mintty.exe
In: false
Out: false // <<<< Thats wrong!
$CONIN Isterm: true
// <<<<--- STUCK at READ here!
Technically speaking, there is something common between git-for-windows and msys2.
winpty
? conpty
? Basically mintty uses "cygwin" ptys, not native Windows consoles, so trying to interact with the attached native Windows console from within it is usually doomed to failure. winpty
is a program that tries to work around this, and conpty
is a new thing that should help, but is still buggy so not enabled by default here (or in git bash).
Personally, I don't use mintty because of this. I either run within the native console host, or now in Windows Terminal.
@gabyx Can you provide equivalent code in C?
I suspect it is the same problem that I have which causes python to report that stdout is not a tty.
Add ConPTY=on
to your minttyrc file.