[jboss-cvs] JBossAS SVN: r109486 - branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/scripts/support.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Nov 26 05:20:46 EST 2010
Author: mlinhard
Date: 2010-11-26 05:20:46 -0500 (Fri, 26 Nov 2010)
New Revision: 109486
Modified:
branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/scripts/support/ShellScriptExecutor.java
Log:
ShellScriptExecutor.runShellCommand
- added capability to return exitCode
- removed unnecessary call to process.exitValue() that always throws IllegalThreadStateException
- replaced 1second wait for OutputPumpers by call to join().
Modified: branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/scripts/support/ShellScriptExecutor.java
===================================================================
--- branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/scripts/support/ShellScriptExecutor.java 2010-11-26 06:35:50 UTC (rev 109485)
+++ branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/scripts/support/ShellScriptExecutor.java 2010-11-26 10:20:46 UTC (rev 109486)
@@ -35,18 +35,18 @@
* Class to execute shell scripts synchronously and collect output
*
* @author Richard Achmatowicz
+ * @author <a href="mailto:mlinhard at redhat.com">Michal Linhard</a>
* @version $Revision: 1.0
*/
public class ShellScriptExecutor extends AbstractShellScriptExecutor {
- public void runShellCommand(String[] commandArray) throws Exception {
- runShellCommand(commandArray, null, null) ;
+ public int runShellCommand(String[] commandArray) throws Exception {
+ return runShellCommand(commandArray, null, null) ;
}
- public void runShellCommand(String[] commandArray, String[] envp) throws Exception {
- runShellCommand(commandArray, envp, null) ;
+ public int runShellCommand(String[] commandArray, String[] envp) throws Exception {
+ return runShellCommand(commandArray, envp, null) ;
}
- public void runShellCommand(String[] commandArray, String[] envp, File workingDir) throws Exception {
-
+ public int runShellCommand(String[] commandArray, String[] envp, File workingDir) throws Exception {
/* create strings to write output to */
outWriter = new StringWriter() ;
outlog = new PrintWriter(outWriter,true);
@@ -59,8 +59,8 @@
try {
process = Runtime.getRuntime().exec(commandArray, envp, workingDir);
} catch (IOException ioe) {
- System.err.println("Could not start command."+ ioe);
- return;
+ System.err.println("Could not start command. "+ ioe);
+ return -1;
}
/* open the streams here */
@@ -73,33 +73,20 @@
Thread errPump = new OutputPumper(errStream, errorlog);
errPump.start();
- /* check for tetrmination of the command */
- int exitCode = 0 ;
+ /* wait for termination */
+ int exitCode = -1;
try {
- exitCode = process.exitValue() ;
- // System.out.println("exit code = " + exitCode) ;
+ exitCode = process.waitFor();
+ outPump.join();
+ errPump.join();
+ } catch (InterruptedException itse) {
+ System.out.println("Error in wait") ;
}
- catch (IllegalThreadStateException itse) {
- System.out.println("Process not yet terminated - waiting") ;
- // only wait if the stuff wa not found? The process has terminated
- // already?
- try {
- process.waitFor();
- } catch (InterruptedException ie) {
- System.out.println("Error in wait") ;
- }
- }
- /* if we don't give the pumpers a little time, we can miss lines */
- try {
- Thread.sleep(1000) ;
- }
- catch(InterruptedException ie) {
- }
-
/* close the streams here */
outlog.close() ;
errorlog.close() ;
closeAllStreams(process) ;
+ return exitCode;
}
}
More information about the jboss-cvs-commits
mailing list