jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1519534 - in /jmeter/trunk: src/jorphan/org/apache/jorphan/exec/SystemCommand.java xdocs/changes.xml
Date Tue, 03 Sep 2013 00:30:39 GMT
Author: sebb
Date: Tue Sep  3 00:30:39 2013
New Revision: 1519534

URL: http://svn.apache.org/r1519534
Log:
SystemCommand should support chaining of commands
Bugzilla Id: 55515

Modified:
    jmeter/trunk/src/jorphan/org/apache/jorphan/exec/SystemCommand.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/jorphan/org/apache/jorphan/exec/SystemCommand.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/jorphan/org/apache/jorphan/exec/SystemCommand.java?rev=1519534&r1=1519533&r2=1519534&view=diff
==============================================================================
--- jmeter/trunk/src/jorphan/org/apache/jorphan/exec/SystemCommand.java (original)
+++ jmeter/trunk/src/jorphan/org/apache/jorphan/exec/SystemCommand.java Tue Sep  3 00:30:39
2013
@@ -18,6 +18,7 @@
 
 package org.apache.jorphan.exec;
 
+import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
@@ -121,6 +122,11 @@ public class SystemCommand {
      * @throws IOException
      */
     public int run(List<String> arguments) throws InterruptedException, IOException
{
+        return run(arguments, stdin, stdout, stderr);
+    }
+
+    // helper method to allow input and output to be changed for chaining
+    private int run(List<String> arguments, InputStream in, OutputStream out, OutputStream
err) throws InterruptedException, IOException {
         Process proc = null;
         final ProcessBuilder procBuild = new ProcessBuilder(arguments);
         if (env != null) {
@@ -128,7 +134,7 @@ public class SystemCommand {
         }
         this.executionEnvironment = Collections.unmodifiableMap(procBuild.environment());
         procBuild.directory(directory);
-        if (stderr == null) {
+        if (err == null) {
             procBuild.redirectErrorStream(true);
         }
         try
@@ -140,19 +146,19 @@ public class SystemCommand {
             final InputStream procIn = proc.getInputStream();
 
             final StreamCopier swerr;
-            if (stderr != null){
-                swerr = new StreamCopier(procErr, stderr);
+            if (err != null){
+                swerr = new StreamCopier(procErr, err);
                 swerr.start();
             } else {
                 swerr = null;
             }
 
-            final StreamCopier swout = new StreamCopier(procIn, stdout);
+            final StreamCopier swout = new StreamCopier(procIn, out);
             swout.start();
             
             final StreamCopier swin;
-            if (stdin != null) {
-                swin = new StreamCopier(stdin, procOut);
+            if (in != null) {
+                swin = new StreamCopier(in, procOut);
                 swin.start();
             } else {
                 swin = null;
@@ -182,6 +188,24 @@ public class SystemCommand {
     }
 
     /**
+     * Pipe the output of one command into another
+     * 
+     * @param arguments1 first command to run
+     * @param arguments2 second command to run
+     * @return exit status
+     * @throws InterruptedException
+     * @throws IOException
+     */
+    public int run(List<String> arguments1, List<String> arguments2) throws InterruptedException,
IOException {
+        ByteArrayOutputStream out = new ByteArrayOutputStream(); // capture the intermediate
output
+        int exitCode=run(arguments1,stdin,out, stderr);
+        if (exitCode == 0) {
+            exitCode = run(arguments2,new ByteArrayInputStream(out.toByteArray()),stdout,stderr);
+        }
+        return exitCode;
+    }
+
+    /**
      * Wait for end of proc execution or timeout if timeoutInMillis is greater than 0
      * @param proc Process
      * @param timeoutInMillis long timeout in ms

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1519534&r1=1519533&r2=1519534&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Tue Sep  3 00:30:39 2013
@@ -419,6 +419,7 @@ Previously the default was 1, which coul
 <li><bugzilla>55451</bugzilla> - Test Element GUI with JSyntaxTextArea
scroll down when text content is long enough to add a Scrollbar</li>
 <li><bugzilla>55513</bugzilla> - StreamCopier cannot be used with System.err
or System.out as it closes the output stream</li>
 <li><bugzilla>55514</bugzilla> - SystemCommand should support arbitrary
input and output streams</li>
+<li><bugzilla>55515</bugzilla> - SystemCommand should support chaining
of commands</li>
 </ul>
 
 <h2>Non-functional changes</h2>



Mime
View raw message