You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2008/03/21 17:02:38 UTC

svn commit: r639690 - /servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/utils/ExecuteCommand.java

Author: gnodet
Date: Fri Mar 21 09:02:34 2008
New Revision: 639690

URL: http://svn.apache.org/viewvc?rev=639690&view=rev
Log:
Fix 'utils exec' command

Modified:
    servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/utils/ExecuteCommand.java

Modified: servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/utils/ExecuteCommand.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/utils/ExecuteCommand.java?rev=639690&r1=639689&r2=639690&view=diff
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/utils/ExecuteCommand.java (original)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/utils/ExecuteCommand.java Fri Mar 21 09:02:34 2008
@@ -18,11 +18,16 @@
  */
 package org.apache.geronimo.gshell.commands.utils;
 
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.util.List;
 
 import org.apache.geronimo.gshell.clp.Argument;
+import org.apache.geronimo.gshell.command.IO;
 import org.apache.geronimo.gshell.command.annotation.CommandComponent;
 import org.apache.geronimo.gshell.common.io.PumpStreamHandler;
+import org.apache.geronimo.gshell.common.io.StreamPumper;
+import org.apache.geronimo.gshell.spring.ProxyIO;
 import org.apache.geronimo.gshell.support.OsgiCommandSupport;
 
 /**
@@ -33,19 +38,36 @@
 @CommandComponent(id="utils:exec", description="Execute system processes")
 public class ExecuteCommand extends OsgiCommandSupport
 {
-    private ProcessBuilder builder;
 
     @Argument(description="Argument", required=true)
     private List<String> args;
 
     protected Object doExecute() throws Exception {
-        assert builder != null;
+        ProcessBuilder builder = new ProcessBuilder(args);
 
         log.info("Executing: {}", builder.command());
 
         Process p = builder.start();
 
-        PumpStreamHandler handler = new PumpStreamHandler(io.inputStream, io.outputStream, io.errorStream);
+        PumpStreamHandler handler = new PumpStreamHandler(io.inputStream, io.outputStream, io.errorStream) {
+            protected Thread createPump(final InputStream in, final OutputStream out, final boolean closeWhenExhausted) {
+                assert in != null;
+                assert out != null;
+                final Thread result = new Thread(new StreamPumper(in, out, closeWhenExhausted)) {
+                    private IO io;
+                    public void start() {
+                        io = ProxyIO.getIO();
+                        super.start();
+                    }
+                    public void run() {
+                        ProxyIO.setIO(io);
+                        super.run();
+                    }
+                };
+                result.setDaemon(true);
+                return result;
+            }
+        };
         handler.attach(p);
         handler.start();