I want to do this through an Ant build script:
$ /bin/sh
$ cd /path/to/executable
$ ./executable.sh
This is what I tried but I think it only executes the cd command:
<exec executable="/bin/sh" os="Mac OS X">
<arg value="-c"/>
<arg value="cd /path/to/executable"/>
<arg value="./executable.sh"/>
</exec>
I am on Mac OS X.
Only the first arg after the -c is run by the shell, hence the behaviour you see. Just put the two commands into one arg, separated by a semicolon:
<exec executable="/bin/sh" os="Mac OS X">
<arg value="-c"/>
<arg value="cd /path/to/executable; ./executable.sh"/>
</exec>
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.
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.
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>
I want ANT to execute a .cmd file on windows machine... but the command prompt should not be displayed. the process should be running in background. Ant should just fire the command and proceed with the next command.
I even tried using the windows "/B" switch, but it did not work.
Does anybody have a suggestion?
Use exec task like that :
<exec executable="cmd" spawn="true">
<arg value="/c"/>
<arg value="foobar.cmd"/>
</exec>
That should be sufficient, otherwise if you need to use start /B ... :
<exec executable="cmd">
<arg value="/c"/>
<arg value="start"/>
<arg value="/b">
<arg value="foobar.cmd"/>
</exec>
See ant manual exec task for details.
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>