Reputation: 764
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%**
Upvotes: 7
Views: 9487
Reputation: 7041
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
Upvotes: 5
Reputation: 705
Are you sure the problem is not in your reading of the variable?
<property environment="env"/>
<property name="MY_VAR" value="${env.MY_VAR}"/>
Upvotes: 0