I saw this command in SO How to filter the xcodebuild command line output?
which shows only the errors and warnings when we do xcodebuild otherwise the xcodebuild commands prints everything to the console regarding what it is doing.
Is there a way I can use grep with xcodebuild in an ant task ?
<exec executable="xcodebuild" failonerror="true">
<arg value="| grep error" />
<arg value="clean" />
<arg value="build" />
</exec>
The exec task above throws error while trying to execute the ant task.
-quiet do not print any output except for warnings and errors
xcodebuild clean build -quiet
it works.
This question might be helpful. I also suppose you need to invoke actions first and then grep. Maybe this will work:
<exec dir="${projectPath}/" executable="bash" failonerror="true">
<arg value="-c"/>
<arg value="xcodebuild clean build | grep error"/>
</exec>
Related
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 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.
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>
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>