currently im calling a batch script(__Make.bat) through exec task which starts GNUMake related tasks.
After i invoke build.xml file directly from the command line the batch script gets called where a new command shell is shown and before the batch script completes its operation the ant execution is closed.
Based on the output of the batch script im calling junit results task for generating the report.
So currently the batch script is independent of ant shell.
Could you please let me know is there any option to control the batch script so that after it completes its operation the junit results gets called.
snippet:
<!-- Macro to execute batch script from every testcase-->
<macrodef name="executeTarget">
<attribute name="option" default="NOT SET"/>
<sequential>
<exec dir="${baseLoc}/Temp/${ant.project.name}/${testDataZipFile}/MakeWare/BCU_MakeWare" executable="cmd" vmlauncher="true" os="Windows XP">
<env key="WAHL" value="#{option}"/>
<arg line="/c "/>
<arg value="start __Make.bat"/>
</exec>
</sequential>
</macrodef>
regards,
kiran
Pass the /WAIT option to start:
<arg value="start /WAIT __Make.bat"/>
Start command: Microsoft's documentation
Related
I am trying to execute an Ant script through jenkins but it fails when it attempts to use webpack...
The ant script's execution task is the following:
<exec executable="webpack.cmd" failonerror="true">
<env key="PROD_ENV" value="true"/>
</exec>
where webpack.cmd has been installed as a global npm module. The module directory has been included in the Path variable and I have even made sure that Jenkins is actually able to see it by doing a trial run inside a Execute windows batch command build step. However when it attempts to execute it via Ant it fails. Could it be a problem with the Ant plugin and its version?
The error i'm getting is the following:
Execute failed: java.io.IOException: Cannot run program "webpack.cmd": CreateProcess error=2, The system cannot find the file specified
webpack.cmd needs to run in a command shell. Try...
<exec executable="cmd" failonerror="true">
<env key="PROD_ENV" value="true"/>
<arg value="/c"/>
<arg value="webpack.cmd"/>
</exec>
You may need to provide the full absolute path to webpack.cmd so cmd.exe can find it.
Is there a way to checkout files from RTC using Ant scripts?. I have a scenario where i need to checkout the files from RTC and build an app using Ant.
It should be possible to invoke scm command through <exec> ant task.
You can see some examples in "Using the SCM Command Line Interface in builds"
<property name="run" value="/path/to/run_and_filter.pl"/>
<property name="scm" value="/path/to/scm"/>
<target name="__scm-checkin">
<!-- Do the initial commit -->
<exec executable="${run}" failonerror="true" outputproperty="cs">
<arg value="${scm} --non-interactive -a n -u y checkin ${roots}"/>
<arg value=" \(([^)]+)\)"/>
</exec>
<!-- Deliver -->
<exec executable="${scm}" failonerror="true">
<arg value="--non-interactive"/>
<arg value="deliver"/>
<arg value="${cs}"/>
</exec>
</target>
Make sure to use scm though, not lscm which starts a damon and can cause the ant task to hang: see "Calling lscm.bat from a build script causes a hang".
RTC does not have a "check-out" operation, which is implicit. It only has a check-in operation. If you want to get code from a repository workspace you can load it using scm command, as described before, or creating a java standalone using Plain API.
my ant was stoped when execute "<exec excultable="c:\myExe.exe"/>",the result code is just "<message priority="error"><![CDATA[Result: 128]]></message>".I don't know what's meaning of that.
I've tried to search some info like: error code 128---no such exe file,but I havn't.
some one could help me to explain what's the meaning?
Thanks
Oh sorry.
More info:
<macrodef name="gtest-layer-macro">
<attribute name="execfile"/>
<attribute name="layerpath" default=""/>
<attribute name="outputDir" default="${basedir}/${reports}/gtest"/>
<attribute name="reportfile" default="#{outputDir}/gtest_report.xml"/>
<sequential>
<check-layer-path layerpath="#{layerpath}"/>
<if>
<and>
<length string="#{execfile}" when="gt" length="0" trim="true"/>
<available file="#{execfile}"/>
</and>
<then>
<var name="##report.dir##" unset="true"/>
<dirname property="##report.dir##" file="#{reportfile}"/>
<mkdir dir="${##report.dir##}"/>
<exec executable="#{execfile}">
<arg value="--gtest_output="xml:#{reportfile}""/>
</exec>
</then>
</if>
</sequential>
</macrodef>
When I run the <exec>, there’s "error Result:128".
The “#{execfile}” is a gtest.exe file(a exe file to test a module),it could run correctly when I double-click it,it could print the unit test result in the console;Run in the CMD with “--gtest_output="xml:#{reportfile}"” is also could print the unit test result in the console,and output a unit test report(a .xml file).And I have changed another .exe instead of the “gtest.exe”,it’s right too.
So,I don’t know where I’m wrong.
An [exec] Result:128 is a process that can't be found/doesn't exist. At least this is what I've found out from my Ant target to kill any remaining processes at the end of certain tests. I get that result when the process I want to kill isn't running. My build log output looks like this;
[shutdown.server] exec
[13:45:33][exec] ERROR: The process "firefox.exe" not found.
[13:45:34][exec] Result: 128
So if that result is from the execution of your .exe then I'd check the path to ensure the exe is available.
I want to know if its possible to get the return value from batch file in Ant build xml.
My batch file returns %ERRORLEVEL% value (batch file returns 2 in my case). I want to know if it's possible to capture this and mark as error in Ant. Below is the code snippet I use:
<exec executable = "cmd">
<arg value="/c"/>
<arg value="C:\workspace\Build\cross_Compile.bat"/>
</exec>
Currently after the batch file call, build is reported as success always. It looks like Ant is not processing the %ERRORLEVEL% or I am not sure. How I can make Ant process the %ERRORLEVEL%?
Use the resultproperty and failonerror. By default, the errocode is ignored.
<property name="Batcherrcode" value="0"/>
<exec executable = "cmd" failonerror="true" resultproperty="Batcherrcode">
<arg value="/c"/>
<arg value="C:\workspace\Build\cross_Compile.bat"/>
</exec>
<echo message="Error Code:=${Batcherrorcode}" />
I have an ant task, and within it I'd like to get the current process id (a la echo $PPID from command line).
I'm running ksh on Solaris, so I thought I could just do this:
<property environment="env" />
<target name="targ">
<echo message="PID is ${env.PPID}" />
<echo message="PID is ${env.$$}" />
</target>
But that didn't work; the variables aren't substituted. Turns out PPID, SECONDS, and certain other env variables don't make it into Ant's representation.
Next I try this:
<target name="targ">
<exec executable="${env.pathtomyfiles}/getpid.sh" />
</target>
getpid.sh looks like this:
echo $$
This gets me the PID of the spawned shell script. Closer, but not really what I need.
I just want my current process ID, so I can make a temporary file with that value in the name. Any thoughts?
You can find PID using java process monitoring tool JPS, then output stream can be filtered and if needed process can be killed. check out this tomcat pid kill script:
<target name="tomcat.kill" depends="tomcat.shutdown">
<exec executable="jps">
<arg value="-l"/>
<redirector outputproperty="process.pid">
<outputfilterchain>
<linecontains>
<contains value="C:\tomcat\tomcat_node5\bin\bootstrap.jar"/>
</linecontains>
<replacestring from=" C:\tomcat\tomcat_node5\bin\bootstrap.jar"/>
</outputfilterchain>
</redirector>
</exec>
<exec executable="taskkill" osfamily="winnt">
<arg value="/F"/>
<arg value="/PID"/>
<arg value="${process.pid}"/>
</exec>
<exec executable="kill" osfamily="unix">
<arg value="-9"/>
<arg value="${process.pid}"/>
</exec>
</target>
Why not just use the tempfile Ant task, instead? It does what you really want to do, while hiding all the gory details.
See http://ant.apache.org/manual/Tasks/tempfile.html.
your second method doesn't get ANT's pid. Change the shell script to (I use bash, I don't know if ksh is the same):
echo "$PPID"