You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Michael Silverman <mi...@gmail.com> on 2005/12/14 01:40:37 UTC

Getting the drive letter and setting windows path

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...)

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).

Thank you very much for any help you can offer,
Michael

Re: Getting the drive letter and setting windows path

Posted by Steve Loughran <st...@apache.org>.
Michael Silverman wrote:

> Actually, Ant runs a task that launches a java app which loads a DLL which
> itself loads more DLL's....
> The first DLL load is not a problem (I'm just passing java.library.path to
> the JVM) but when that DLL tries to loads the other DLL's, it searches them
> in the windows path (this is a normal behavior which has nothing to do with
> Java / Ant).
> So what I want is to append the DLL's dir to the windows path just before I
> run the task but it has to be done in the same process of Ant in order to be
> visible to the first DLL (which runs in a child process created by the Ant
> task).
> 
> I hope that's clear enough.
> 

<java> has an <env> attribute. set the path there. You do not need to 
(and cannot) alter the env of ant while it is running

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Getting the drive letter and setting windows path

Posted by Stefan Bodewig <bo...@apache.org>.
On Wed, 14 Dec 2005, Michael Silverman <mi...@gmail.com>
wrote:

> So what I want is to append the DLL's dir to the windows path just
> before I run the task but it has to be done in the same process of
> Ant in order to be visible to the first DLL (which runs in a child
> process created by the Ant task).

Can't you use Ant to resolve the directory to your DLL using
 <property location...>?  Ant knows how to resolve the file and create
an absolute path using the correct drive letter so you wouldn't have
to do so.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Getting the drive letter and setting windows path

Posted by Michael Silverman <mi...@gmail.com>.
Hi Ivan,

Thank you very much for your help.

I will try ant-contrib and your macro and hopefully it will solve my first
problem.


> 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.
>
>
Actually, Ant runs a task that launches a java app which loads a DLL which
itself loads more DLL's....
The first DLL load is not a problem (I'm just passing java.library.path to
the JVM) but when that DLL tries to loads the other DLL's, it searches them
in the windows path (this is a normal behavior which has nothing to do with
Java / Ant).
So what I want is to append the DLL's dir to the windows path just before I
run the task but it has to be done in the same process of Ant in order to be
visible to the first DLL (which runs in a child process created by the Ant
task).

I hope that's clear enough.

Any other ideas how to set the path through Ant?

Thanks,
Michael

Re: Getting the drive letter and setting windows path

Posted by Ivan Ivanov <ra...@yahoo.com>.
Hello Michael,

--- Michael Silverman <mi...@gmail.com>
wrote:

> 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>:

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

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

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

Regards
Ivan

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org