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

前端 未结 3 1733
难免孤独
难免孤独 2021-01-12 13:57

I\'m porting a Linux script to Windows & MinGW, which accesses the Android phone through ADB.

Sometime I need to pass the Android\'s file path as ADB command lin

相关标签:
3条回答
  • 2021-01-12 14:35

    Please, can we get the terminology right here? MinGW does no path translation, such as you describe; it is the MSYS build environment, provided by MinGW.org as a companion to MinGW, which does this, so I guess you are actually using the version of MSYS supplied with Git for Windows.

    I'm pleased that you have found the magic bullet which works in your case, but please be aware that there are some corner cases in which this "double slash" trick doesn't suffice; if you run into one of these, you may wish to consider Cygwin as an alternative hosting shell on Windows.

    0 讨论(0)
  • 2021-01-12 14:38

    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.

    0 讨论(0)
  • 2021-01-12 14:39

    Just found starting the double-slash is the charm.

    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
    
    0 讨论(0)
提交回复
热议问题