Index: /trunk/gli/src/org/greenstone/gatherer/shell/GShell.java
===================================================================
--- /trunk/gli/src/org/greenstone/gatherer/shell/GShell.java	(revision 5886)
+++ /trunk/gli/src/org/greenstone/gatherer/shell/GShell.java	(revision 5887)
@@ -89,4 +89,22 @@
     /** Element in process type name enumeration */
     static public String GSHELL_EXPORT = "gshell_export";
+
+    /** Determine if the given process is still executing. It does this by attempting to throw an exception - not the most efficient way, but the only one as far as I know
+     * @param process the Process to test
+     * @return true if it is still executing, false otherwise
+     */
+    static public boolean processRunning(Process process) {
+	boolean process_running = false;
+	try {
+	    process.exitValue(); // This will throw an exception if the process hasn't ended yet.
+	}
+	catch(IllegalThreadStateException itse) {
+	    process_running = true;
+	}
+	catch(Exception exception) {
+	    Gatherer.printStackTrace(exception);
+	}
+	return process_running;
+    }
     
     /** Constructor gatherer all the data required to create a new process, and emit meaningfull messages.
@@ -161,12 +179,63 @@
 	    Process prcs = rt.exec(args);
 	    InputStreamReader eisr = new InputStreamReader( prcs.getErrorStream() );
-	    InputStreamReader stdinisr = new InputStreamReader( prcs.getInputStream() );
-	    BufferedReader ebr = new BufferedReader( eisr );
-	    BufferedReader stdinbr = new BufferedReader( stdinisr );
+	    InputStreamReader stdisr = new InputStreamReader( prcs.getInputStream() );
+	    //BufferedReader ebr = new BufferedReader( eisr );
+	    //BufferedReader stdinbr = new BufferedReader( stdinisr );
 	    // Captures the std err of a program and pipes it into std in of java
+	    
+	    StringBuffer eline_buffer = new StringBuffer();
+	    StringBuffer stdline_buffer = new StringBuffer();
+	    while(processRunning(prcs) && !hasSignalledStop()) {
+		// Hopefully this doesn't block if the process is trying to write to STDOUT.
+		if(eisr.ready()) {
+		    int c = eisr.read();
+		    if(c == '\n' || c == '\r') {
+			if(eline_buffer.length() > 0) {
+			    String eline = eline_buffer.toString();
+			    System.err.print("*");
+			    if(progress != null) {
+				progress.parse(eline);
+			    }
+			    if(bos != null) {
+				try {
+				    bos.write(eline.getBytes(), 0, eline.length());
+				}
+				catch(Exception error) {
+				    Gatherer.printStackTrace(error);
+				}
+			    }
+			    fireMessage(type, typeAsString(type) + "> " + eline, status);
+			    eline = null;
+			    eline_buffer = new StringBuffer();
+			}
+		    }
+		    else {
+			eline_buffer.append((char)c);
+		    }
+		}
+		// Hopefully this won't block if the process is trying to write to STDERR
+		if(stdisr.ready()) {
+		    int c = stdisr.read();
+		    if(c == '\n' || c == '\r') {
+			if(stdline_buffer.length() > 0) {
+			    String stdline = stdline_buffer.toString();
+			    System.err.print("+");
+			    fireMessage(type, typeAsString(type) + "> " + stdline, status);
+			    stdline = null;
+			    stdline_buffer = new StringBuffer();
+			}
+		    }
+		    else {
+			stdline_buffer.append((char)c);
+		    }
+		}
+	    }
+
+	    /** This causes Phind to deadlock
 	    String eline = null;
 	    String stdinline = null;
-	    while (((eline = ebr.readLine()) != null || (stdinline = stdinbr.readLine()) != null) && !hasSignalledStop()) {
+	    while ((( eline = ebr.readLine()) != null || (stdinline = stdinbr.readLine()) != null) && !hasSignalledStop()) {
 		if(eline != null) {
+		    System.err.print("*");
 		    if(progress != null) {
 			progress.parse(eline);
@@ -183,7 +252,9 @@
 		}
 		if(stdinline != null) {
+		    System.err.print("+");
 		    fireMessage(type, typeAsString(type) + "> " + stdinline, status);
 		}
 	    }
+	    */
 
 	    if(!hasSignalledStop()) {
@@ -203,4 +274,5 @@
 		// I need to somehow kill the child process. Unfortunately Thread.stop() and Process.destroy() both fail to do this. But now, thankx to the magic of Michaels 'close the stream suggestion', it works fine (no it doesn't!)
 		prcs.getInputStream().close();
+		prcs.getErrorStream().close();
 		prcs.getOutputStream().close();
 		prcs.destroy();
