tags:

views:

373

answers:

2

I am trying to invoke an ANT target from Windows (right-click) file context menu.

I have setup the registry entries to invoke a batch script which invokes my ANT EXEC target.

I need to pass the path of the file (on which user right-clicked) to my ANT target. So I am using %~dp1 to set an ANT properties in my bat script:

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

resulting in:

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

The problem is %~dp1 returns a string with "\" as file separator. But ANT EXEC task wants "/"

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

Any suggestions how to get around this path separators?

+1  A: 
set AntPath="D:\Project\Rel L\"
set AntPath=%AntPath:\=/%
set AntPath=%AntPath::/=:%

gives

set AntPath="D:\Project\Rel L\"

set AntPath="D:/Project/Rel L/"

set AntPath="D:Project/Rel L/"

Andy Morris
set AntPath=%AntPath:\=/% did the trick...
Nirmal Patel
+1  A: 

If you are running on Windows Ant will happily accept OS directory separator which is \. Upon examination of the output of your program I see that the path separators are missing: you have D:ProjectRel not D:\Project\Rel. I may only guess that you are trying to exec a Cygwin program. Cygwin programs will use \ as an escape character. Therefore you need to use a <pathconvert> property to adjust the directory separators.

Code snippet below illustrates how to do this

<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}"/>

And here is the output of this run:

[echo] system-path-filename=D:\Project\Rel L\file
[echo] unixized-filename=D:/Project/Rel L/file
Alexander Pogrebnyak
Yes, I am trying to run JAVA to run the weblogic deployer <exec executable="${JAVA1.5_HOME}/java">I got around passing UNIX-ized path using replace in batch file.
Nirmal Patel