Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 line option.

However, when invoking the ADB.exe, MinGW translates it to Windows' path.

For example,

adb shell cat /proc/version

Is translated as follows, resulting "No such file or directory" error in Android.

adb shell cat C:/Program Files (x86)/Git/proc/version

I found double-quotation helps to prevent that.

adb shell "cat /proc/version"

But is there any global siwtches or env variables to prevent MinGW for this converstion ?

The MinGW I'm using came with the "Git for Windows" package.

EDITED : I also hit another scnario, I cannot work-around with the double quotation.

$ adb push test1.mp3 /data
failed to copy 'test1.mp3' to 'C:/Program Files (x86)/Git/data': No such file or directory

$ adb push test1.mp3 "/data"
failed to copy 'test1.mp3' to 'C:/Program Files (x86)/Git/data': No such file or directory
like image 639
Tony Avatar asked Feb 16 '15 02:02

Tony


1 Answers

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
like image 179
Tony Avatar answered Sep 20 '22 20:09

Tony