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>
Related
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 & 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
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>
I want to run a VBScript file from an Ant script. How can I do that?
Have a look at the exec task. It allows you to execute a system command from your Ant script.
EDIT:
An example could be:
<target name="RunVbScript">
<exec executable="cscript">
<arg value="MyScript.vbs"/>
<arg value="argument 1" />
<arg value="argument 2" />
<arg value="argument n" />
</exec>
</target>
I'm trying to exec a VS build using incredibuild within my ANT script, but For some reason the exec task fails with the following error:
'Win32' is not recognized as an internal or external command
when I use the following code:
<arg line='buildconsole solution.sln /rebuild /cfg="Release|Win32"' />
I think the ant script may be treating the '|' as a delimter or something...
Any ideas how I could get this to work?
I've also tried the following, but nothing gets me closer:
<arg line='buildconsole solution.sln /rebuild /cfg="Release|Win32"' />
<arg value="buildconsole solution.sln /rebuild /cfg="Release|Win32"" />
<arg value="buildconsole solution.sln /rebuild /cfg="Release|Win32"" />
You need to escape the pipe symbol by preceding it with ^. So:
<arg line='buildconsole solution.sln /rebuild /cfg="Release^|Win32"' />
EDIT:
Are you sure the caret doesn't work? It seems to in this sample ant file:
<?xml version="1.0" encoding="UTF-8"?>
<project name="Test" default="build" basedir=".">
<target name="build">
<exec executable="cmd">
<arg line="/k echo cfg="Release^|Win32""/>
</exec>
</target>
</project>
Hmm... I just tried it again and it worked, but only after I changed to
<arg value="buildconsole solution.sln /rebuild /cfg=Release^|Win32" />
so I guess the quotes around Release^|Win32 wasn't necessary if I use value.
Thanks a bunch!
I think the problem is that the Windows command prompt sees the | and treats it as a "pipe" operator. Perhaps escape the pipe by using:
<arg line='buildconsole solution.sln /rebuild /cfg="Release\|Win32"' />