How can an ANT build script kill a Windows process? How can an ANT build script kill a Windows process? windows windows

How can an ANT build script kill a Windows process?


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>


This is an old post and normally I use the timeout="milliseconds" , but for a long running process, I have found that the best way of killing an Ant launched process (especially java.exe threads within Eclipse) is to use pskill.exe.

Just load pskill64.exe into the project directory and run the following Ant build.

<project name="project" default="shutdown.java.tasks" basedir="../"><target name="shutdown.java.tasks">    <exec executable="path.to.pskill.in.your.project\pskill64">        <arg value="java.exe" />    </exec></target>

Typical output is:

shutdown.java: [exec] PsKill v1.16 - Terminates processes on local or remote systems [exec] Copyright (C) 1999-2016  Mark Russinovich [exec] Sysinternals - www.sysinternals.com [exec] 8 processes named java.exe killed.

BUILD SUCCESSFULTotal time: 387 milliseconds