ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ivan Ivanov <>
Subject Re: Getting the drive letter and setting windows path
Date Wed, 14 Dec 2005 01:15:19 GMT
Hello Michael,

--- Michael Silverman <>

> Hi All,
> I have two questions and I would really appreciate
> your assistance.
> 1. How do I get the drive letter which ant is
> running from (under windows of
> course)?
>     Something like getting the first char of
> ${basedir} is good enough for
> me (I think...)
You can do it using <propertyregexp> from ant-contrib
or if you want pure Ant solution you can use the
following <macrodef>:

    <macrodef name="getDriveLetter">
        <attribute name="absPath"
	<attribute name="result"/>
	    <echo file=".tempfile">@{absPath}</echo>
	    <replaceregexp file=".tempfile" match="\\(.*)"
	    <loadfile srcfile=".tempfile"
	    <delete file=".tempfile" failonerror="false"/>

    <getDriveLetter result="drive"/>
    <echo>$${drive} is ${drive}</echo>

There may be some trick with <pathconvert> as well.

> 2. Is there a way to set the windows path through
> ant? It doesn't have to be
> permanent,
>    I just want to append a dir to the windows path
> during the running of ant
> (because of a DLL issue).
>    I tried to use the exec task but it didn't work:
> I couldn't execute 'set'
> because it is not
>    an executable file and if I execute 'cmd.exe'
> with arguments 'set
> Path=...' , then the path
>    is only changed in the cmd.exe process and not
> outside of it (the change
> is not visible
>    to ant after cmd.exe has ended).

I suppose you are calling a windows command with
<exec>. You can use <exec>'s nested element <env> and
pass through it the desired env variable.

Hope this helps


Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 

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

View raw message