ANT:exec command - ant

i have a set of Environment variables in ANT exec command as follows,
<exec dir="${basedir}/src/" command="/usr/local/covidien/HDE/x86.linux2.6/bin/idlpp -S -l java ${basedir}/src/HelloWorldData.idl" >
<env key="OSPL_HOME" value="/usr/local/covidien/HDE/x86.linux2.6"/>
<env key="OSPL_TARGET" value="x86.linux2.6"/>
<env key="PATH" value="$OSPL_HOME/bin:$PATH"/>
<env key="LD_LIBRARY_PATH" value="$OSPL_HOME/lib:$LD_LIBRARY_PATH"/>
<env key="CPATH" value="$OSPL_HOME/include:$OSPL_HOME/include/sys:$CPATH"/>
<env key="OSPL_TMPL_PATH" value="$OSPL_HOME/etc/idlpp"/>
<env key="OSPL_URI" value="$OSPL_HOME/etc/idlpp"/>
<env key="CLASSPATH" value="$OSPL_HOME/jar/dcpssaj.jar:$CLASSPATH"/>
<env key="CLASSPATH" value="$OSPL_HOME/jar/dcpscj.jar:$CLASSPATH"/>
</exec>
but it throws error as error while loading shared libraries: libddsutil.so:.I have an external lib which contains *.so files.I need to include it with exec command.How to add external lib with exec command

Unix environment variables do not work within the ANT file, need to be imported as ANT properties. Also the arguments to the command must be specified separately. See the exec task doco
Try something like this:
<property environment="env"/>
<exec dir="${basedir}/src/" executable="/usr/local/covidien/HDE/x86.linux2.6/bin/idlpp">
<arg line="-S -l java ${basedir}/src/HelloWorldData.idl" >
<env key="OSPL_HOME" value="/usr/local/covidien/HDE/x86.linux2.6"/>
<env key="OSPL_TARGET" value="x86.linux2.6"/>
<env key="PATH" value="${env.OSPL_HOME}/bin:${env.PATH}"/>
<env key="LD_LIBRARY_PATH" value="${env.OSPL_HOME}/lib:${env.LD_LIBRARY_PATH}"/>
<env key="CPATH" value="${env.OSPL_HOME}/include:${env.OSPL_HOME}/include/sys:${env.CPATH}"/>
<env key="OSPL_TMPL_PATH" value="${env.OSPL_HOME}/etc/idlpp"/>
<env key="OSPL_URI" value="${env.OSPL_HOME}/etc/idlpp"/>
<env key="CLASSPATH" value="${env.OSPL_HOME}/jar/dcpssaj.jar:${env.CLASSPATH}"/>
</exec>

Related

How can I use ant <exec> to execute commands on Windchill?

Need to run this below command in the Ant exec tag.
windchill ext.cummins.securityLabel.CumminsLoadAgreement -d
%WT_HOME%/loadFiles/ext/cummins/Agreements/AgreementList/Agreement_Loader.xlsx -u wcadmin -p wcadmin
You can make use of Java Task in your ant script to perform this.
Use the below script
<java classname="ext.cummins.securityLabel.CumminsLoadAgreement" fork="true">
<arg value="${username}"/>
<arg value="${password}"/>
<arg value="-d"/>
<arg path="${Your_Custom_Directory}/${Custom_file}"/>
</java>
In a your ant xml file, define a ant target with the tag , the path for Windchill Home is accessible with the variable ${env.WT_HOME}
<project name="YourProjectName" default="YourTargetName" basedir=".">
<target name="YourTargetName">
<exec executable="windchill" dir="." failonerror="true">
<arg line="ext.cummins.securityLabel.CumminsLoadAgreement -d ${env.WT_HOME}/loadFiles/ext/cummins/Agreements/AgreementList/Agreement_Loader.xlsx -u wcadmin -p wcadmin" />
</exec>
</target>
</project>
From a windchill shell you can then run the target as "usual":
ant -f yourFile.xml YourTargetName
Tipp: if you name your ant file build.xml, you even do not need to specify it as parameter.

How to run multiple commands with arguments from single Ant exec task

On windows, I am trying to execute two commands (.cmd and .exe) later requiring parameters,in one exec() task. This is to avoid using two shell ,however only first command is getting executed.
Following is the Ant snippet
<exec executable="cmd" dir="C:\PROGRA~1\IBM\IIB\10.0.0.7\server\bin\">
<arg value="/c mqsiprofile.cmd & C:\PROGRA~1\IBM\IIB\10.0.0.7\server\bin\mqsideploy.exe" />
<arg value="IIBNODE1" />
<arg value="-e" />
<arg value="default" />
<arg value="-a" />
<arg value="${bar.name}" />
</exec>
I also ran it without &amp and replacing "PROGRA~1" with "Program Files", still the same issue. Please suggest.
You can include both in a single target:
<target name="execute.this">
<exec dir="${testworkspace}\${moduleName}"
executable="cmd" failonerror="true"
output="${testworkspace}/${moduleName}/BuildConsole_TC${tc_num}.log"
resultproperty="execrc">
<arg value="/c echo Download Status is ${DownloadStatus}"/>
<exec dir="${testworkspace}\${moduleName}"
executable="cmd" failonerror="true"
output="${testworkspace}/${moduleName}/BuildConsole_TC${tc_num}.log"
resultproperty="execrc">
<arg value="/c Load.bat ${moduleName} ${Intapp} ${CcvStatus}"/>
</exec>
Or better yet, just use the <echo> task:
<echo message="/c echo Download Status is ${DownloadStatus}"/>
<exec dir="${testworkspace}\${moduleName}"
executable="cmd"
failonerror="true"
output="${testworkspace}/${moduleName}/BuildConsole_TC${tc_num}.log"
resultproperty="execrc">
<arg value="/c Load.bat ${moduleName} ${Intapp} ${CcvStatus}"/>
</exec>
If you need the output of the echo task in the same file, you can use the file parameter in the echo command, and the append parameter in the exec task.
Ref: How to run multiple commands from ant exec task

Run buildfile with parameters under Linux

I created an Ant task that runs buildfile (dfs-build.xml) with parameters. It works well under OS Windows. But, I would like ANT task runs under Linux. Any ideas?
<exec executable="cmd">
<arg value="/c"/>
<arg value="${ant.basedir}\bin\ant -Dproperty.files.dir=${property.files.dir} -Dbasedir=${antscripts.basedir}/../DocumentumCoreProject/dfs6.7 -Dmodule.name=rbacs -f ${antscripts.basedir}\sub_ANTs\Create_EAR_WAR\dfs-build.xml generate"/>
</exec>
The exec task is simpler under Linux:
<exec executable="${ant.basedir}\bin\ant" osfamily="unix">
<arg value="-Dproperty.files.dir=${property.files.dir} -Dbasedir=${antscripts.basedir}/../DocumentumCoreProject/dfs6.7 -Dmodule.name=rbacs -f ${antscripts.basedir}\sub_ANTs\Create_EAR_WAR\dfs-build.xml generate"/>
</exec>
Another cross-platform option is to run the build within the same ANT process
<subant antfile="{antscripts.basedir}\sub_ANTs\Create_EAR_WAR\dfs-build.xml" target="generate">
<property name="property.files.dir" value="${property.files.dir}"/>
<property name="basedir" value="${antscripts.basedir}/../DocumentumCoreProject/dfs6.7"/>
<property name="module.name" value="rbacs"/>
</subant>

Running a .cmd file from Ant

Is it possible to run a command (.cmd file) from Ant? Would I need to write Java code for this?
<exec executable="cmd" os="Windows XP">
<arg value="/C"/>
<arg value="command to run"/>
</exec>
You can do this by using the exec task. From the ant exec documentation:
Note that .bat files cannot in general by executed directly. One normally needs to execute the command shell executable cmd using the /c switch.
So you would need to do something like:
<exec executable="cmd">
<arg value="/c"/>
<arg value="batchfile.cmd"/>
</exec>
Note that by doing this you have created a dependency of running your ant script in windows.
Adding to eradicus answer, you can also execute .bat, .cmd, ... from any directory with argument on your Window machine by
<target name="test">
<exec executable="cmd" dir="C:/Users/mydir/">
<arg value="/C" />
<arg value="myjob.bat arg1 arg2" />
</exec>
</target>

Executing command line code in an ant build file

How can I execute following command line code in an ant build file?
cd backend/doctrine/
export PC_ZEND_ENV=testing
php doctrine migrations:migrate << EOF
y
EOF
The solution
With the feedback I've got I figured out the following working exec command.
<exec dir="backend/doctrine" executable="php">
<env key="PC_ZEND_ENV" value="development" />
<arg line="doctrine migrations:migrate" />
<arg value="<< Y" />
</exec>
Use the exec task. The result should be something like the following (untested):
<exec dir="backend/doctrine" executable="./doctrine">
<arg line="migrations:migrate << EOF"/>
<env key="PC_ZEND_ENV" value="testing"/>
</exec>

Resources