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%**
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.
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).
Use the /C
option of cmd.exe
.
<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>
run:
[exec] SOME_VAL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With