Windows - run apps from bash

Issue description

Whenever you run certain Windows tools from the Git for Windows bash terminal (Mingw64), it always gives a message such as the following:

$ winget --version
bash: /c/Users/.../AppData/Local/Microsoft/WindowsApps/winget: Permission denied

You’ll see that the affected programs look like 0 byte executables. There seems to be some dark magic for Microsoft apps which bash doesn’t understand. This magic is called App Execution Aliases and can be solved in the Git for Windows bash terminal:

The issue is that Cygwin’s spawn() implementation tries to read the file (looking for the PE header?) and fails, and so returns that Permission Denied error. These are not real files on disk, unfortunately, but reparse points, so all you can do with them is execute (CreateProcess). Probably the best fix is for Cygwin to skip the PE header check if the extension is .exe, but checking for IO_REPARSE_TAG_APPEXECLINK in the reparse tag and then going ahead with launching it would also work.

Edit: Of course, once Cygwin has the fix it’ll have to flow down. It may make more sense to fix it further downstream first, but I was told that the original code is part of Cygwin and just inherited by MinGW and Git Bash.

Issue: https://github.com/git-for-windows/git/issues/2675

Workaround

An easy workaround is to add the following to your .bashrc to wrap the command using winpty (included by default in most Windows Bash setups):

alias winget="winpty winget"