Bug 22710 - Allow exec to detach a process
Summary: Allow exec to detach a process
Status: RESOLVED DUPLICATE of bug 5907
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.5.4
Hardware: PC Linux
: P3 enhancement (vote)
Target Milestone: 1.6
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-08-25 20:13 UTC by Ives Landrieu
Modified: 2008-02-22 12:18 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ives Landrieu 2003-08-25 20:13:13 UTC
I was having problems using ant to start a j2ee server (Jonas). The problem was that ant 
kept waiting for the process to finish (which is strange, as it was started by a script in the 
background). Anyway, this does seem to occur to other people too (I found some references 
in the mailing list with people having the same kind of problem when starting tomcat).  
The suggested solution that seems to be wildly circulated on the mailing lists is a hacked 
version of the Exec task (apropriately called 'spawn'). Therefore I propose to allow an 
optional boolean parameter called 'detach' to the exec task (defaulting to false) which 
controls this kind of behaviour. I have implemented this and provide the patch (base version 
is ant 1.5.4) below. I'm not sure that it will behave properly under all circumstances (I'm not 
an expert in forked processes behaviour and handling), but it does solve my problem (which 
is a good start ;-) ). 
 
regards, 
Ives Landrieu 
 
------------------- patch follows ----------------------- 
--- apache-ant-1.5.4/src/main/org/apache/tools/ant/taskdefs/ExecTask.java	2003-08-12 
14:11:06.000000000 +0200 
+++ apache-ant-1.5.4.patched/src/main/org/apache/tools/ant/taskdefs/ExecTask.java	
2003-08-25 21:38:48.000000000 +0200 
@@ -98,6 +98,7 @@ 
     private String resultProperty; 
     private boolean failIfExecFails = true; 
     private boolean append = false; 
+	private boolean detach = false; 
  
     /**  
      * Controls whether the VM (1.3 and above) is used to execute the 
@@ -126,6 +127,24 @@ 
     } 
  
     /** 
+     * Controls detachement of the executing process. 
+     * 
+     * @since Ant 1.6 
+     */ 
+    public void setDetach(boolean value) { 
+        detach = value; 
+    } 
+ 
+    /** 
+     * Controls detachement of the executing process. 
+     * 
+     * @since Ant 1.6 
+     */ 
+    public boolean getDetach() { 
+        return detach; 
+    } 
+ 
+    /** 
      * The command to execute. 
      */ 
     public void setExecutable(String value) { 
@@ -307,6 +326,7 @@ 
         exe.setAntRun(getProject()); 
         exe.setWorkingDirectory(dir); 
         exe.setVMLauncher(vmLauncher); 
+		exe.setDetach(detach); 
         String[] environment = env.getVariables(); 
         if (environment != null) { 
             for (int i = 0; i < environment.length; i++) { 
diff --exclude='*flc' --exclude='*~' -Naur 
apache-ant-1.5.4/src/main/org/apache/tools/ant/taskdefs/Execute.java 
apache-ant-1.5.4.patched/src/main/org/apache/tools/ant/taskdefs/Execute.java 
--- apache-ant-1.5.4/src/main/org/apache/tools/ant/taskdefs/Execute.java	2003-08-12 
14:11:08.000000000 +0200 
+++ apache-ant-1.5.4.patched/src/main/org/apache/tools/ant/taskdefs/Execute.java	
2003-08-25 21:35:40.000000000 +0200 
@@ -96,6 +96,7 @@ 
  
     /** Controls whether the VM is used to launch commands, where possible */ 
     private boolean useVMLauncher = true; 
+	private boolean detach = false; 
  
     private static String antWorkingDirectory = System.getProperty("user.dir"); 
     private static CommandLauncher vmLauncher = null; 
@@ -394,6 +395,17 @@ 
     } 
  
     /** 
+     * Controls whether ant will wait for the launched process to finish. 
+     * @param useVMLauncher true if exec should launch through thge VM, 
+     *                   false if the shell should be used to launch the 
+     *                   command. 
+     */ 
+ 
+    public void setDetach(boolean detach) { 
+        this.detach = detach; 
+    } 
+ 
+    /** 
      * Creates a process that runs a command. 
      * 
      * @param project the Project, only used for logging purposes, may be null. 
@@ -445,16 +457,20 @@ 
         if (watchdog != null) { 
             watchdog.start(process); 
         } 
-        waitFor(process); 
- 
-        // remove the process to the list of those to destroy if the VM exits 
-        // 
-        processDestroyer.remove(process); 
+		if(!detach) { 
+			waitFor(process); 
+			 
+			// remove the process to the list of those to destroy if the VM exits 
+			// 
+			processDestroyer.remove(process); 
+		} 
  
         if (watchdog != null) { 
             watchdog.stop(); 
         } 
-        streamHandler.stop(); 
+		if(!detach) { 
+			streamHandler.stop(); 
+		} 
         if (watchdog != null) { 
             watchdog.checkException(); 
         }
Comment 1 Stefan Bodewig 2003-08-26 07:36:57 UTC
CVS HEAD's <exec> has a spawn attribute.

*** This bug has been marked as a duplicate of 5907 ***