You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Rich Wagner <ri...@hotmail.com> on 2003/04/07 02:06:35 UTC

"destroy"-ing an Ant exec doesn't destroy what Ant is "exec"-ing...

Hi,

I've developed a simple Java-based GUI for invoking Ant.  That GUI uses 
"Runtime.exec" to run Ant in "Process" objects.  The GUI also includes a 
"Stop" button which executes the "destroy" method on the currently executing 
Ant process.

That much works fine.  However, say my GUI invokes Ant and it, in turn, uses 
the "exec" task to run another Process.  (In my particular case, my build 
file is using "exec" to run a Windows-based "build.exe" command-line build 
utility for creating an InstallAnywhere installer: each build is lengthy and 
consumes much of the available processor resources.)

If I hit the "Stop" button while my Ant build file is in the middle of 
"exec"-ing that "build.exe" sub-Process, the "destroy" call *DOES* kill Ant, 
but Ant does not - in turn - "destroy" the "build.exe" sub-process.  (As a 
result, even though I hit "Stop", I have to wait several minutes for the 
"build.exe" sub-process to terminate normally - or I can use the quite 
user-unfriendly method of manually killing the "build.exe" sub-Process 
myself...)

My guess is Ant isn't even given an oppurtunity to respond to "destory" and 
do pre-"destroy" cleanup when the Ant Process before quitting.  But I'm not 
sure if that's really the case, or if Ant *COULD* potentially "catch" some 
Throwable ("ThreadDeath" ?) that occurs as a part of the "destroy" call, and 
handle the situation more correctly by in turn destroying the "build.exe" 
sub-process before Ant gives up the ghost.  (In other words, is this an 
"Ant" bug?  Can it do anything between a "destroy" of it and it's own 
destruction ?)

Anyway, details aside, is there maybe a different way (other than "exec") 
that I can run "Ant" so that my GUI can stop BOTH Ant AND anything 
sub-Process it's in the middle of "exec"-ing ?

Thanks,
Rich Wagner


_________________________________________________________________
Tired of spam? Get advanced junk mail protection with MSN 8. 
http://join.msn.com/?page=features/junkmail


Re: "destroy"-ing an Ant exec doesn't destroy what Ant is "exec"-ing...

Posted by Stefan Bodewig <bo...@apache.org>.
On Mon, 07 Apr 2003, Rich Wagner <ri...@hotmail.com> wrote:

> If I hit the "Stop" button while my Ant build file is in the middle
> of "exec"-ing that "build.exe" sub-Process, the "destroy" call
> *DOES* kill Ant, but Ant does not - in turn - "destroy" the
> "build.exe" sub-process.

Ant will try to kill the spawned processes in it's shutdown hook
(given a Java VM recent enough to support shutdown hooks and Ant >=
1.5 that is).

I've found that at least on Unix shutdown hooks will not be called by
the VM if you kill the spawned process with enough violence (i.e. 
kill -9 doesn't, a simple kill usually does).

If Ant's VM has no chance to call the shutdown hooks, there probably
isn't anything you can do.

> Anyway, details aside, is there maybe a different way (other than
> "exec") that I can run "Ant"

Sure.  Look what Main does and clone it (don't use Main directly, its
not suitable for that).

Most Ant IDE integrations do not execute Ant in a separate VM.  You
may be able to get some ideas of the Open Source versions of existing
IDE integrations (NetBeans, Eclipse, the JBuilder AntRunner and
probably others are Open Source).

Stefan