I found this useful when piping information between java calls.

The outputproperty is used in the fashion as Exec, but for Java. Currently only 
implemented for calles when fork=true.



Dennis Adams

 
--- org\apache\tools\ant\taskdefs\Java.java     Thu May  2 14:44:19 2002
+++ org\apache\tools\ant\taskdefs\Java.java.orig        Thu Oct 11 23:58:28 2001
@@ -72,16 +72,14 @@
  * @author <a href="mailto:[EMAIL PROTECTED]">Stefan Bodewig</a>
  */
 public class Java extends Task {
-    private static String lSep = System.getProperty("line.separator");
+
     private CommandlineJava cmdl = new CommandlineJava();
     private boolean fork = false;
     private File dir = null;
     private File out;
     private PrintStream outStream = null;
     private boolean failOnError = false;
-    private String outputprop; 
-    private ByteArrayOutputStream baos; 
-
+    
     /**
      * Do the execution.
      */
@@ -253,14 +251,6 @@
     }
 
     /**
-     * Property name whose value should be set to the output of
-     * the process
-     */
-    public void setOutputproperty(String outputprop) {
-      this.outputprop = outputprop;
-    }
-
-    /**
      * -mx or -Xmx depending on VM version
      */
     public void setMaxmemory(String max){
@@ -323,16 +313,13 @@
         FileOutputStream fos = null;
         try {
             Execute exe = null;
-            if (out != null) {
-              fos = new FileOutputStream(out);
-              exe = new Execute(new PumpStreamHandler(fos), null);
-            } else if (outputprop != null) { 
-              baos = new ByteArrayOutputStream();
-              exe = new Execute(new PumpStreamHandler(baos), null);
-            } else {
-               exe = new Execute(new LogStreamHandler(this, Project.MSG_INFO,
+            if (out == null) {
+                exe = new Execute(new LogStreamHandler(this, Project.MSG_INFO,
                                                        Project.MSG_WARN), 
-                                  null);  
+                                  null);
+            } else {
+                fos = new FileOutputStream(out);
+                exe = new Execute(new PumpStreamHandler(fos), null);
             }
             
             exe.setAntRun(project);
@@ -348,27 +335,7 @@
             
             exe.setCommandline(command);
             try {
-                int rVal = exe.execute();
-
-                if (baos != null) 
-                {
-                  BufferedReader in = new BufferedReader(new 
StringReader(baos.toString()));
-                  String line = null;
-                  StringBuffer val = new StringBuffer();
-                  while ((line = in.readLine()) != null) 
-                  {
-                    if (val.length() != 0) 
-                    {
-                      val.append(lSep);
-                    }
-                      val.append(line);
-                  } 
-
-
-                  project.setProperty(outputprop,val.toString());
-                }
-              
-                return rVal;
+                return exe.execute();
             } catch (IOException e) {
                 throw new BuildException(e, location);
             }

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

Reply via email to