msys2.github.io icon indicating copy to clipboard operation
msys2.github.io copied to clipboard

mintty doesn't set terminal io properly

Open julie777 opened this issue 2 years ago • 13 comments

This appears to be a bug in the msys mintty compile. I can run the same version of mintty (3.5.2) from cygwin and it works correctly.

Reproduce by starting MSYS2 MSYS from the start menu on Windows 10. The terminal window opens and bash starts correctly.

Run the windows version of python

 python -c "import os,sys; print(os.isatty(sys.stderr.fileno()))"

and it returns False. Doing the same thing with cygwin returns True.

Possibly related? When MSYS bash starts most of the windows path has been removed instead of converted. All that gets converted is

/c/Windows/System32
/c/Windows
/c/Windows/System32/Wbem
/c/Windows/System32/WindowsPowerShell/v1.0

I don't know if this is by design or a problem.

julie777 avatar Feb 26 '22 19:02 julie777

msys2 does not enabled ConPTY feature by default. Whereas cygwin does. To enable ConPTY by-default in msys2, close all the msys2 terminal windows, set MSYS=enable_pcon variable in Control Panel, then run any msys2 terminal.

Biswa96 avatar Feb 26 '22 19:02 Biswa96

What do you mean enable the variable in the Control Panel? Do you mean add it to the system or user environment variables?

What is the reason for not enabling ConPTY by default?

julie777 avatar Feb 26 '22 19:02 julie777

Do you mean add it to the system or user environment variables?

Yes, systempropertiesadvanced.exe

What is the reason for not enabling ConPTY by default?

Some programs like autotools, git etc. have issues with it. But things are being fixed quickly.

Biswa96 avatar Feb 26 '22 20:02 Biswa96

Run the windows version of python

Which python are you running? What does python -c "import sys; print(sys.version)" show?

Biswa96 avatar Feb 26 '22 20:02 Biswa96

Which python are you running? I am running python310 from an install on Windows.

What does python -c "import sys; print(sys.version)" show? 3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit (AMD64)]

I found that there is a mingw64.ini and an msys2.ini that have MSYS2_PATH_TYPE=inherit commented out. I assume that I can un-comment it and bash will inherit the windows path.

I also added MSYS=enable_conpty but that didn't seem to work to enable tty in python.

julie777 avatar Feb 26 '22 20:02 julie777

BTW, I am only looking at msys2 for a solution because I use git-bash from Git for Windows which is based on msys2. That is where I first found the problem.

Is there a list somewhere of all the config variables that can be used in msys2.ini?

julie777 avatar Feb 26 '22 20:02 julie777

I've wanted to document the options that are allowed in MSYS environment variable, but haven't found time to do so. The closest thing that exists is the documentation for the corresponding CYGWIN variable for cygwin: https://cygwin.com/cygwin-ug-net/using-cygwinenv.html. But there are some differences/additions in msys2.

jeremyd2019 avatar Feb 26 '22 20:02 jeremyd2019

I also added MSYS=enable_conpty but that didn't seem to work to enable tty in python.

it's enable_pcon not conpty

jeremyd2019 avatar Feb 26 '22 20:02 jeremyd2019

I just found out that the shortcut created in the start menu during installation is a special terminal shortcut with a terminal tab. It doesn't read config file in C:\msys64\mingw64.ini. If I just run "C:\msys64\mingw64.exe" it does read the config file and MSYS2_PATH_TYPE=inherit works.

julie777 avatar Feb 26 '22 20:02 julie777

I also added MSYS=enable_conpty but that didn't seem to work to enable tty in python.

it's enable_pcon not conpty

I mistyped. This is what I have in the ini file

MSYS=enable_pcon

julie777 avatar Feb 26 '22 20:02 julie777

BTW, I am only looking at msys2 for a solution because I use git-bash from Git for Windows which is based on msys2. That is where I first found the problem.

In Git for Windows there is an option in the installer.

jeremyd2019 avatar Feb 26 '22 20:02 jeremyd2019

I just found out that the shortcut created in the start menu during installation is a special terminal shortcut with a terminal tab. It doesn't read config file in C:\msys64\mingw64.ini. If I just run "C:\msys64\mingw64.exe" it does read the config file and MSYS2_PATH_TYPE=inherit works.

My mistake, it does read the ini file, but it overrides the MSYS2_PATH_TYPE=inherit from .ini file, because it is running C:\msys64\msys2_shell.cmd -msys.

The good news, is that I found the correct variable to set isatty=True and it can be put in the .ini files in c:\msys64\ or in ./config/mintty/config in my home directory. The variable is ConPTY=on

julie777 avatar Feb 26 '22 20:02 julie777

BTW, the list of all the mintty config variable is at https://mintty.github.io/mintty.1.html#CONFIGURATION

julie777 avatar Feb 26 '22 21:02 julie777