Author: sgoeschl Date: Tue Feb 17 23:51:27 2009 New Revision: 745302 URL: http://svn.apache.org/viewvc?rev=745302&view=rev Log: [EXEC-33] Throwing an IllegalArgumentException when System.in is used - this is a workaround until the problem is properly fixed.
Modified: commons/proper/exec/trunk/src/changes/changes.xml commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/PumpStreamHandler.java commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java Modified: commons/proper/exec/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/changes/changes.xml?rev=745302&r1=745301&r2=745302&view=diff ============================================================================== --- commons/proper/exec/trunk/src/changes/changes.xml (original) +++ commons/proper/exec/trunk/src/changes/changes.xml Tue Feb 17 23:51:27 2009 @@ -24,6 +24,11 @@ </properties> <body> <release version="1.0.0" date="As in SVN" description="Sandbox release"> + <action dev="sgoeschl" type="fix" issue="EXEC-33"> + Using System.in for child process will actually hang your application - + see JIRA for more details. Since there is no easy fix an + IllegalRuntimeException is thrown when System.in is passed. + </action> <action dev="sgoeschl" type="fix" due-to="Luc Maisonobe" issue="EXEC-35"> Fixing a few findbugs issues. </action> Modified: commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/PumpStreamHandler.java URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/PumpStreamHandler.java?rev=745302&r1=745301&r2=745302&view=diff ============================================================================== --- commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/PumpStreamHandler.java (original) +++ commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/PumpStreamHandler.java Tue Feb 17 23:51:27 2009 @@ -55,6 +55,13 @@ */ public PumpStreamHandler(final OutputStream out, final OutputStream err, final InputStream input) { + + // see EXEC-33 + if(input == System.in) { + String msg = "Using System.in is currently not supported since it would hang your application (see EXEC-33)."; + throw new IllegalArgumentException(msg); + } + this.out = out; this.err = err; this.input = input; Modified: commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java?rev=745302&r1=745301&r2=745302&view=diff ============================================================================== --- commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java (original) +++ commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java Tue Feb 17 23:51:27 2009 @@ -373,16 +373,22 @@ /** * Start a process and connect stdin, stdout and stderr. This - * test currenty hang .... + * test currenty hang. Therefore we throw an IllegalArgument + * Exception to notify the user. */ - public void doNotTestExecuteWithStdin() throws Exception + public void testExecuteWithStdin() throws Exception { - CommandLine cl = new CommandLine(testScript); - PumpStreamHandler pumpStreamHandler = new PumpStreamHandler( System.out, System.err, System.in ); - DefaultExecutor executor = new DefaultExecutor(); - executor.setStreamHandler( pumpStreamHandler ); - int exitValue = executor.execute(cl); - assertFalse(exec.isFailure(exitValue)); + try { + CommandLine cl = new CommandLine(testScript); + PumpStreamHandler pumpStreamHandler = new PumpStreamHandler( System.out, System.err, System.in ); + DefaultExecutor executor = new DefaultExecutor(); + executor.setStreamHandler( pumpStreamHandler ); + int exitValue = executor.execute(cl); + assertFalse(exec.isFailure(exitValue)); + } + catch(IllegalArgumentException e) { + assertTrue( e.getMessage().indexOf("EXEC-33") >= 0); + } } /**