Search code examples
windowsantcommand-linebuild

How can an ANT build script kill a Windows process?


I'm working on extending an ANT build script to allow a TeamCity build agent to run Selenium tests.

In doing so there is a server required to start with selenium which isn't shutdown at the end. So I added an extra target to execute a taskkill on the exe name at the end of every TC build.

Does taskkill need the absolute path to the exe, because the following isn't working;

<target name="shutdown.server" depends="init.properties" description="Shutdown the server after Selenium">
    <exec osfamily="windows" executable="cmd.exe" spawn="true">
        <arg line="taskkill /f /t /im app.exe"/>
    </exec>
</target>

The process seems to have a few children which is why I've gone with /f /t but as I say, none of them shutdown at the moment.


Solution

  • Well that was easy;

    <target name="shutdown.server" depends="init.properties" description="Shutdown the server after Selenium">
        <exec executable="taskkill">
            <arg line="/im app.exe /f /t"/>
        </exec>
    </target>