ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "didge" <>
Subject cygpath task
Date Wed, 31 Dec 2003 18:53:51 GMT

The $ANT_HOME/bin/ant shell script automatically converts a number of paths
from cygwin to windows when executed in a cygwin shell, including JAVA_HOME,

However, there are often paths defined in my cygwin shell that also need to
be converted.  To this end, I've written a task to convert cygwin paths to
windows paths, but only when executed in a cygwin shell.  Below is a
detailed description and example.

Is this something of general interest to ant users?

It works like this:

  <cygpath properties="[properties]"/>

where [properties] is a comma separated list of properties containing simple
or compound cygwin paths.  The value of each property is converted in place.

Here is an example that demonstrates the task with both a simple and a
compound path:

<project name="cygpath example" default="cygpath">
  <taskdef name="cygpath" classname="foundrylogic.cyg.task.Cygpath"/>
  <target name="cygpath">
    <property name="somepath0" value="/cygdrive/c/foo"/>
    <property name="somepath1" value="/cygdrive/c/bar:/cygdrive/c/oof"/>

    <echo message="before cygpath:"/>
    <echo message="somepath0='${somepath0}'"/>
    <echo message="somepath1='${somepath1}'"/>

    <cygpath properties="somepath0, somepath1"/>

    <echo message="after cygpath:"/>
    <echo message="somepath0='${somepath0}'"/>
    <echo message="somepath1='${somepath1}'"/>


Here is the output after running it:

Buildfile: build.xml

     [echo] before cygpath:
     [echo] somepath0='/cygdrive/c/foo'
     [echo] somepath1='/cygdrive/c/bar:/cygdrive/c/oof'
     [echo] after cygpath:
     [echo] somepath0='c:\foo'
     [echo] somepath1='c:\bar;c:\oof'


A couple of other notes:
- Cygpath modifies the value of the user properties given to it.
- Cygpath only executes when run in a cygwin shell.  If run from a dos shell
or a non-cygwin unix shell, Cygpath does nothing.  Detection of the cygwin
shell is based on the property cygwin.user.home being defined by the
$ANT_HOME/bin/ant script.  If this property is not defined, then Cygpath is
effectively a no-op.
- Cygpath delegates the actual conversion to the cygpath executable, so
cygpath must be in your PATH.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message