DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=22710>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=22710

Allow exec to detach a process

           Summary: Allow exec to detach a process
           Product: Ant
           Version: 1.5.4
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: Enhancement
          Priority: Other
         Component: Core tasks
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


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(); 
         }

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to