2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018

01/24/2003: Ant; An Example of The Ant Condition Task

I needed to test the condition code returned by stopping the Apache service so that I could delete the log files. I settled on the following script:
  <property name="apache.service"    value="Apache" />
  <property name="sleep.in.seconds"  value="4" />

  <target name="shutdown_apache" description="stops the Apache service.">
    <exec executable="c:/WINNT/system32/net.exe" resultproperty="apache.stop.resultproperty" outputproperty="apache.stop.outputproperty">
      <arg value="stop" />
      <arg value="${apache.service}" />
    </exec>
    <condition property="apache.not.stopped">
      <equals arg1="${apache.stop.resultproperty}" arg2="2" />
    </condition>
    <antcall target="sleep_apache_stop" />
  </target>

  <target name="sleep_apache_stop" unless="apache.not.stopped">
    <echo>Sleeping for ${sleep.in.seconds} seconds.</echo>
    <sleep seconds="${sleep.in.seconds}" />
  </target>


subscribe via RSS