I created a macro to help with this:
<macrodef name="check-cmd-output">
<attribute name="cmd" />
<attribute name="contains-string" />
<attribute name="property" />
<sequential>
<local name="temp-command-output" />
<exec executable="cmd" outputproperty="temp-command-output">
<arg value="/c @{cmd}" />
</exec>
<condition property="@{property}" >
<contains string="${temp-command-output}" substring="@{contains-string}" />
</condition>
</sequential>
</macrodef>
Then you can use it like this:
<target name="check-mysql-started" depends="init" >
<check-cmd-output cmd="mysqladmin ping" contains-string="mysqld is alive" property="mysql-started" />
</target>
and then do something similar to the following:
<target name="start-mysql" depends="check-mysql-started" unless="mysql-started">
</target>
, Ant . , .