These are two ant tasks:
<target name="hg.add" >
<exec dir="." executable="hg">
<arg line="add ${reports-summary}" />
</exec>
</target>
<target name="hg.add">
<exec executable="/bin/sh">
<arg value="-c"/>
<arg value="hg add ${reports-summary}"/>
</exec>
</target>
This two tasks seem to have the same function. But why the second one needs to write"/bin/sh" and "-c"?
The -c is just an argument to the executable it does not mean anything special to the ant exec task.
The first target is running the hg executable directly.
The second target is running the Linux/Unix shell command (/bin/sh) and passing it the -c argument which tells the shell to execute a command given in the next argument. So this will run the same command as the first target, but the shell command may set up things like environment variables before running the command.
Related
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.
I try to start JBoss with ant.
When i execute this script :
<target name="start-jboss" >
<exec executable="${jboss.bin.dir}\run.bat" >
<arg line="--configuration=Myserver -b localhost" />
</exec>
</target>
JBoss is blocking at this step :
[exec] 15:52:55,373 INFO [AjpProtocol] Initializing Coyote AJP/1.3 on ajp-localhost%2F127.0.0.1-8009
But when i run the run.bat it works... Its the same when i add spawn="true" in exec.
I think that the problem comes from eclipse...
Thanks
To run a batchfile use cmd as executable, something like :
<exec dir"yourworkingdir" executable="cmd" failonerror="true">
<arg line="/c ${jboss.bin.dir}\run.bat --configuration=Myserver -b localhost"/>
</exec>
if arg line=... doesn't work, use arg value=... for every parameter.
EDIT : if you have trouble using the batchfile, why not get rid of using that addtional batchfile and use the java task straightforward as explained here ?
I have an exiting ant build that is called via ant -lib lib -f test_build.xml
I wanted to add one more <target> section to be run after the existing one finishes. I did some research and found ant manual for exec and even a question here on SO. After some reading I added new target to this existing build but it didn't work.
I tried to create new build file only with my target. It doesn't work either. Although the ant run finishes with message BUILD SUCCESSFUL
Total time: 0 seconds
If I run my ruby script from a command line it works. I tried to create bat file that would call my ruby script with the same result. If I call the bat file from dos window it works.
My ant run build file looks like
<project name="RunRubyExample">
<target name="calling ruby " >
<exec executable="ruby.exe">
<arg value="C:\EduTester\others\afterant.rb 1 2 tri four"/>
</exec>
</target>
<target name="calling batach">
<exec executable="cmd">
<arg value="/c"/>
<arg value="C:\EduTester\others\rubruby.bat 1 2 tri four"/>
</exec>
</target>
</project>
Apache Ant(TM) version 1.8.2 compiled on December 20 2010
on Windows XP
It looks like you're passing a single arg value with embedded spaces
<arg value="C:\EduTester\others\afterant.rb 1 2 tri four"/>
Is that right? Or should it be either an arg line:
<arg line="C:\EduTester\others\afterant.rb 1 2 tri four"/>
or multiple arg values:
<arg value="C:\EduTester\others\afterant.rb"/>
<arg value="1"/>
<arg value="2"/>
<arg value="tri"/>
<arg value="four"/>
There needs to be specified target that needs to be run
either by <project name="RunRubyExample" default="callingruby">
or when calling the ant build file. Where we pass the target name we want to be run as an argument. ant -lib lib callingruby
Writing a Simple Buildfile
Thank you #Steve
In IntelliJ IDEA I have this task in my Ant script
<target name="emulator-logcat">
<exec command="adb" spawn="false" osfamily="windows">
<arg value="-e"/>
<arg value="shell"/>
<arg value="logcat"/>
</exec>
</target>
It works but command output sent to IDEA ant window, not in Windows console window. How i can forward command output into new Windows console window as if i start this command from cmd.exe?
Problem resolved:
I create runner.bat file witch contains %* and call it like this
<target name="emulator-logcat">
<exec command="cmd.exe" spawn="true" osfamily="windows">
<arg line="/c start runner.bat adb -e shell logcat"/>
</exec>
</target>
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>