views:

71

answers:

1

I am writing a directory path to a text file from ant, which is later read by a Java Application to find another file.

In my ant script I have:

<property name="fulltrainer.dir"  location="${trainer.dir}" />

<echo file="${trainer.dir}/properties/commonConfig.properties"># KEY         VALUE
CurrentBuildFile=${fulltrainer.dir}\current_build</echo>

in the build.properties file trainer.dir is set to:

trainer.dir=../trainer

It ends up writing:

# KEY        VALUE
CurrentBuildFile=C:\Workspaces\ralph\trainer\current_build

to the commonConfig.properties file.

I need it to write:

# KEY        VALUE
CurrentBuildFile=C:\\Workspaces\\ralph\\trainer\\current_build

or, I need it to write:

# KEY        VALUE
CurrentBuildFile=C:/Workspaces/ralph/trainer/current_build

How can I do that?

+2  A: 

This looks a lot like this question: http://stackoverflow.com/questions/1799684/ant-basedir-slashes-escape-problem

So, try using the pathconvert task.

<pathconvert targetos="unix" property="fulltrainer.unix_dir">
    <path location="${trainer.dir}"/>
</pathconvert>

<property name="cf.props" value="${trainer.dir}/properties/commonConfig.properties"/>
<echo file="${cf.props}" message="# KEY         VALUE"/>
<echo file="${cf.props}" append="yes" message="CurrentBuildFile=${fulltrainer.unix_dir}/current_build"/>
Andy
How did you add the source code formatting to my post? I can't seem to figure out it out.
Andy
@Andy - I thought it looked ok - when you're in the markdown editor you should be able to use the row of buttons above that allow you to apply formatting to the selected text in the edit box. See http://stackoverflow.com/editing-help for some info. I was hoping to be able to make a small edit to get rid of the horizontal scroll bar, but did't want to change much. I added the `append` attribute to the second echo - may not be necessary, but without it the file will be truncated by the second echo.
martin clayton
Aah, thanks for the tip and thanks for the fix. I never use echo to write to text files so that bug creeped in.
Andy