Search code examples
antenvironment-variablesexecdevenv

How do I export environment variables from the Ant 'exec' task?


I am using Ant under WinXp to build MSVisual c++ projects.

To access "devenv.com", being computer-independent, I would like to use the vsvars32.bat script. Unfortunately, it seems that environment variables are defined only in the "exec" scope.

Example:

<exec executable='"${env.VS90COMNTOOLS}vsvars32.bat/>
<echo message="${DevEnvDir}" />
<echo message="${env.DevEnvDir}" />
<property environment="env2"/>
<echo message="${env2.DevEnvDir}" />

I never get the expected result.

How can I use the "vsvars32.bat" script and access to its env. vars? Is there better way to achieve this?


Solution

  • You can create a small batch file that runs your ant script and in that batch file execute vsvars32.bat before calling ant.

    @echo off
    
    setlocal
    
    set TEMP_HOME=%~dp0
    
    call "%VS90COMNTOOLS%\vsvars32.bat"
    
    call "%ANT_HOME%\bin\ant.bat" %*
    
    endlocal