2009-11-03 89 views
0

我试图从Windows(右键单击)文件上下文菜单中调用ANT目标。从BAT脚本将文件路径传递给ANT

我已经设置了注册表项来调用一个调用我的ANT EXEC目标的批处理脚本。

我需要将文件的路径(用户右键单击)传递给我的ANT目标。所以我用%〜DP1在我的蝙蝠脚本中设置的ANT属性:

Set tobeusedfilepath=%~dp1 
Set tobeusedfile=%~n1 

导致:

tobeusedfilepath=D:\Project\Rel L\ 
tobeusedfile=file 

的问题是%〜DP1返回与“\”的字符串作为文件分隔符。但ANT EXEC任务想要“/”

[exec] '-source' 
[exec] 'D:ProjectRel L/file' 
[exec] ...... 
[exec] The file, 'D:ProjectRel L/file', does not exist. 

任何建议如何绕过此路径分隔符?

回答

3
set AntPath="D:\Project\Rel L\" 
set AntPath=%AntPath:\=/% 
set AntPath=%AntPath::/=:% 

给出

组AntPath = “d:\项目\相对大号\”

组AntPath = “d:/项目/相对L /”

组AntPath =” D:Project/Rel L /“

+0

集AntPath =%A​​ntPath:\ = /%的伎俩...... – 2009-11-04 06:00:10

2

如果您在Windows上运行,Ant将高兴地接受操作系统目录分隔符\。 检查你的程序的输出后,我看到路径分隔符丢失了:你有D:ProjectRel而不是D:\Project\Rel。我只能猜测你正在尝试exec a Cygwin程序。 Cygwin程序将使用\作为转义字符。因此,您需要使用<pathconvert>属性来调整目录分隔符。

下面的代码片段说明如何做到这一点

<property name="tobeusedfilepath" location="D:\Project\Rel L\"/> 
<property name="tobeusedfile" value="file"/> 

<property name="system-path-filename" 
    location="${tobeusedfilepath}/${tobeusedfile}" 
/> 

<pathconvert property="unixized-filename" targetos="unix"> 
    <path location="${system-path-filename}"/> 
</pathconvert> 

<echo message="system-path-filename=${system-path-filename}"/> 
<echo message="unixized-filename=${unixized-filename}"/> 

这里是本次运行的输出:

[echo] system-path-filename=D:\Project\Rel L\file 
[echo] unixized-filename=D:/Project/Rel L/file 
+0

是的,我试图运行JAVA来运行weblogic deployer 我绕过在批处理文件中使用替换传递UNIX-ized路径。 – 2009-11-04 10:03:48

相关问题