How to prevent MSYS to convert the file path for an external program

But is there any global switches or env variables to prevent MinGW for this conversion ?

Yes. Use this environment variable:

MSYS_NO_PATHCONV=1

e.g.

MSYS_NO_PATHCONV=1 adb shell cat /proc/version

Beware: programs might not work properly they expect Windows paths.

To work around this you can use escaping as mentioned on the documentation page (look at the bottom):

adb shell cat //proc\version

Rule: first / of parameter is duplicated, rest / are replaced with \

Depending on escaping (e.g. in .sh scripts) used you might need to duplicate \ character:

adb shell cat //proc\\version

This way only parameters you wrote with extra / prefix will be passed without conversion to Windows paths.


Just found starting the double-slash is the charm.

https://web.archive.org/web/20201112005258/http://www.mingw.org/wiki/Posix_path_conversion

An argument starting with 2 or more / is considered an escaped Windows style switch and will be passed with the leading / removed and all \ changed to /.

Except that if there is a / following the leading block of /, the argument is considered to be a UNC path and the leading / is not removed.

| Argument from MSYS program | Sent to native Windows program as | Sent to native Windows program as
| //foobar                   | /foobar                           | double /  prevents conversion
| //foo\bar                  | /foo/bar                          | \  converted to /
| //foo/bar                  | //foo/bar                         | interpreted as UNC path, leading /  not removed