Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] ConsoleOutput Lines


Hi,

I seem to recall a discussion about consoles on the list post 1.0.1, so all this may be water under the bridge but we had a problem where errors were getting corrupted in the console and the task view because of bad interleaving of stdout and stderr.

All this comes from the way the two streams are mingled into one in CommandLauncher. Basically if you are not going to buffer streams by line, (the ideal solution) you are going to have to at least keep reading until the stream goes dry. Attached is the patch we are using to fix this against 1.0.1. The line buffing would be "better" in some cases, but this seems to work just fine.

Thanks!
-Chris
songer@xxxxxxxxxxxxx
director of platform engineering
voice: 408 327 7341 fax: 408 986 8919
diff -r -u xide/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CommandLauncher.java xide_compare/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CommandLauncher.java
--- xide/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CommandLauncher.java	Tue Mar 11 13:52:08 2003
+++ xide_compare/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CommandLauncher.java	Thu Jul 17 10:58:58 2003
@@ -6,6 +6,8 @@
  */
  
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.PipedInputStream;
 import java.io.PipedOutputStream;
@@ -132,7 +134,7 @@
 
 		PipedOutputStream errOutPipe = new PipedOutputStream();
 		PipedOutputStream outputPipe = new PipedOutputStream();
-		PipedInputStream errInPipe, inputPipe;
+		InputStream errInPipe, inputPipe;
 		try {
 			errInPipe = new PipedInputStream(errOutPipe);
 			inputPipe = new PipedInputStream(outputPipe);
@@ -145,23 +147,25 @@
 		closure.runNonBlocking();
 		byte buffer[] = new byte[1024];
 		int nbytes;
+		int errbytes;
 		while (!monitor.isCanceled() && closure.isAlive()) {
 			nbytes = 0;
+			errbytes = 0;
 			try {
-				if ( errInPipe.available() > 0 ) {
-					nbytes = errInPipe.read(buffer);
-					err.write(buffer, 0, nbytes);
-					err.flush();
-				}
-				if ( inputPipe.available() > 0 ) {
+				while ( inputPipe.available() > 0 ) {
 					nbytes = inputPipe.read(buffer);
 					output.write(buffer, 0, nbytes);
 					output.flush();
 				}
+				while ( errInPipe.available() > 0 ) {
+					errbytes = errInPipe.read(buffer);
+					err.write(buffer, 0, errbytes);
+					err.flush();
+				}
 			} catch( IOException e) {
 			}
 			monitor.worked(0);
-			if (nbytes == 0) {
+			if (nbytes == 0 && errbytes == 0) {
 				try {
 						Thread.sleep(DELAY);
 				} catch (InterruptedException ie) {

Back to the top