Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setting env variable with ant's exec task - doesn't seem to work

When I try to set some varible with ant's exec task, it doesn't seem to set to my required value. Not sure what's wrong here.

It works perfectly file when I set & echo from command line with cmd.

<exec executable="cmd">
    <arg value="set"/>
    <arg value="MY_VAR=SOME_VAL"/>
</exec>
-->
<echo message="MY_VAR is set to %MY_VAR%"/>

And output looks like:

exec
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\MY_PROJ_BASE_DIR_HERE>
echo
MY_VAR is set to **%MY_VAR%**
like image 873
user1587504 Avatar asked Nov 11 '13 08:11

user1587504


People also ask

How do I call ant target from command line?

To run the ant build file, open up command prompt and navigate to the folder, where the build. xml resides, and then type ant info. You could also type ant instead. Both will work,because info is the default target in the build file.

Can I use variables in .ENV file?

You can set default values for environment variables using a .env file, which Compose automatically looks for in project directory (parent folder of your Compose file).


1 Answers

Use the /C option of cmd.exe.

build.xml

<project name="ant-exec-cmd-with-env-key" default="run">
    <target name="run">
        <exec executable="cmd" failonerror="true">
            <env key="MY_VAR" value="SOME_VAL"/>
            <arg value="/c"/>
            <arg value="echo %MY_VAR%"/>
        </exec>
    </target>
</project>

Output

run:
     [exec] SOME_VAL
like image 86
Chad Nouis Avatar answered Nov 15 '22 07:11

Chad Nouis