winpty icon indicating copy to clipboard operation
winpty copied to clipboard

Version 0.4.3 that comes with git bash 2.14.1 cannot execute cmd.exe

Open tarruda opened this issue 7 years ago • 6 comments

This was tested on windows 7 pro with latest updates.

Every time I type winpty cmd.exe in git bash prompt, it will exit immediately with no error message. I also notice that it creates an .exe subdirectory in the current directory, because after the second winpty cmd.exe it reports an error: "A subdirectory or file .exe already exists"

Other commands such as python.exe/node.exe/powershell.exe seem to work fine.

tarruda avatar Aug 11 '17 12:08 tarruda

The problem reproduces in MSYS2 without the Git-for-Windows packaging. The root cause is this MSYS2 patch which uses backslashes instead of forward slashes.

https://github.com/Alexpux/MSYS2-packages/blob/ec549593cd9874c801b3a95106d032d23b3ac0b8/winpty/0002-fix-path-conversion.patch#L38

Maybe the fix for https://github.com/rprichard/winpty/issues/81 / https://github.com/rprichard/winpty/issues/98 probably contributes to the issue by making winpty use absolute paths more often.

With the MSYS2 patch, winpty-agent.exe runs C:/Windows/System32/cmd.exe. With upstream winpty, it would instead run C:\Windows\System32\cmd.exe. cmd.exe does not like being started with forward slashes. It seems to interpret the absolute path as the command /c md .exe. e.g.:

C:\Users\rprichard>C:/Windows/System32/cmd.exe
A subdirectory or file .exe already exists.

C:\Users\rprichard>cmd /cmd.exe
A subdirectory or file .exe already exists.

C:\Users\rprichard>cmd /c md .exe
A subdirectory or file .exe already exists.

Upstream winpty should use MSYS2's special path conversion somehow, but AFAIK, there's no public API for it exposed from MSYS-2.0.dll. I suppose I should just copy what MSYS2-packages does and import the CC0-marked path_conv.cpp files.

rprichard avatar Aug 12 '17 05:08 rprichard

Related to https://github.com/rprichard/winpty/issues/88.

rprichard avatar Aug 12 '17 05:08 rprichard

Hello Richard,

what needs to be done to fix this? Do you need some help with this?

lanoxx avatar Dec 14 '17 12:12 lanoxx

Any progress?

noxware avatar Dec 03 '19 04:12 noxware

+1

vipzen avatar Feb 13 '20 23:02 vipzen

As pointed by https://github.com/msys2/MSYS2-packages/issues/411#issuecomment-372585320 , I managed to fix this issue by not installing the package from the msys2 repository (i.e., pacman -S winpty), but downloading directly the binary from the winpty release page: https://github.com/rprichard/winpty/releases image

  1. pacman -R winpty
  2. wget https://github.com/rprichard/winpty/releases/download/0.4.3/winpty-0.4.3-msys2-2.7.0-x64.tar.gz
  3. tar -xvf winpty-0.4.3-msys2-2.7.0-x64.tar.gz
  4. cd winpty-0.4.3-msys2-2.7.0-x64/bin
  5. cp * /usr/bin

Now it correctly opens cmd.exe from bash with $ winpty cmd.exe.

evandrocoan avatar Apr 11 '21 19:04 evandrocoan