如何防止MSYS转换外部程序的文件路径 [英] How to prevent MSYS to convert the file path for an external program

查看:77
本文介绍了如何防止MSYS转换外部程序的文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Linux脚本移植到Windows& MinGW,可通过ADB访问Android手机.

有时候我需要将Android的文件路径作为ADB命令行选项传递.

但是,当调用ADB.exe时,MinGW会将其转换为Windows的路径.

例如,

adb shell cat /proc/version

翻译如下,导致Android中出现无此类文件或目录"错误.

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

我发现双引号可以防止这种情况.

adb shell "cat /proc/version"

但是是否有全局标记或env变量来阻止MinGW进行此对话?

我正在使用的MinGW附带了"Git for Windows"软件包.

我也遇到了另一个问题,我无法解决双引号.

$ 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

解决方案

刚发现以双斜杠开头就是魅力.

http://www.mingw.org/wiki/Posix_path_conversion

以2个或多个/开头的参数被认为是Windows样式的转义参数,将在删除前导/并将所有\更改为/的情况下传递.

除非在/的前导块之后有/,否则该参数被视为UNC路径,并且不删除前导/.

| 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

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

解决方案

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

这篇关于如何防止MSYS转换外部程序的文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆