Index: /main/trunk/gli/src/org/greenstone/gatherer/greenstone/Plugins.java
===================================================================
--- /main/trunk/gli/src/org/greenstone/gatherer/greenstone/Plugins.java	(revision 31775)
+++ /main/trunk/gli/src/org/greenstone/gatherer/greenstone/Plugins.java	(revision 31776)
@@ -165,4 +165,5 @@
 		// Create the process.
 		SafeProcess process = new SafeProcess((String[]) args.toArray(new String[] { }));
+		process.setSplitStdErrorNewLines(true);
 
 		// run the SafeProcess
@@ -174,4 +175,6 @@
 		// get the result: We expect XML to have come out of the process std error stream.
 		pluginfo_xml = process.getStdError();
+		// make sure to have parsed out any lines preceding the XML content
+		pluginfo_xml = XMLTools.readXMLStream(pluginfo_xml).toString();
 		///System.err.println("*********\nPluginInfo, got:\n" + pluginfo_xml + "\n**********\n");
 	    }
@@ -236,8 +239,9 @@
 		args.add("-listall");
 		args.add("-xml");
-
+		
 		// Run the pluginfo.pl process:
 		// Create the process.
 		SafeProcess process = new SafeProcess((String[]) args.toArray(new String[] { }));
+		process.setSplitStdErrorNewLines(true);
 
 		// run the SafeProcess
@@ -249,11 +253,12 @@
 		// get the result: We expect XML to have come out of the process std error stream.	
 		xml = process.getStdError();
-
+		// make sure to parse out any lines before the XML content, else running "gli -debug" results in an XML error:
 		// for pluginfo.pl -listall, we see a "AutoloadConverters" (PDFBox) message
-		// before actual XML output, which breaks XML parsing. Get rid of output before "<?xml"
-		int startIndex = xml.indexOf("<?xml");
-		if(startIndex != 0) {
-		    xml = xml.substring(startIndex);
-		}
+		// before actual XML output, which breaks XML parsing. 
+		// This gets rid of output before "<?xml" in the way that the code did before the change to SafeProcess
+		// Then we can call the same from method RemoteGreenstoneServer.java, so that running "client-gli -debug"
+		// will work too.
+		xml = XMLTools.readXMLStream(xml).toString();
+		
 		///System.err.println("*********\nPluginsList, got:\n" + xml + "\n**********\n");
 	    }
Index: /main/trunk/gli/src/org/greenstone/gatherer/remote/RemoteGreenstoneServer.java
===================================================================
--- /main/trunk/gli/src/org/greenstone/gatherer/remote/RemoteGreenstoneServer.java	(revision 31775)
+++ /main/trunk/gli/src/org/greenstone/gatherer/remote/RemoteGreenstoneServer.java	(revision 31776)
@@ -44,4 +44,5 @@
 import org.greenstone.gatherer.util.UnzipTools;
 import org.greenstone.gatherer.util.Utility;
+import org.greenstone.gatherer.util.XMLTools;
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.methods.PostMethod;
@@ -682,4 +683,22 @@
 	gliserver_in.close();
 
+	
+	int startIndex = command_output_buffer.indexOf("<?xml");
+	if(startIndex > 0) { // not -1, so "<?xml" is present, and not 0, so not at start
+
+	    // iff dealing with XML, make sure to parse out any lines preceding the XML content
+	    command_output_buffer = XMLTools.readXMLStream(command_output_buffer.toString());
+	    /*if(DebugStream.isDebuggingEnabled()) {
+		String prefix = command_output_buffer.substring(0, startIndex);
+		DebugStream.println("Removing the following found before start of XML:");
+		DebugStream.println("---------------------------------");
+		DebugStream.println(prefix);
+		DebugStream.println("---------------------------------");
+	    }
+	    // remove the prefix
+	    return command_output_buffer.substring(startIndex); // remove anything before the start of XML
+	    */
+	}
+	
 	return command_output_buffer.toString();
     }
Index: /main/trunk/gli/src/org/greenstone/gatherer/util/XMLTools.java
===================================================================
--- /main/trunk/gli/src/org/greenstone/gatherer/util/XMLTools.java	(revision 31775)
+++ /main/trunk/gli/src/org/greenstone/gatherer/util/XMLTools.java	(revision 31776)
@@ -733,10 +733,28 @@
 	static public StringBuffer readXMLStream(InputStream input_stream)
 	{
+	    StringBuffer xml = new StringBuffer("");
+	    try {
+		InputStreamReader isr = new InputStreamReader(input_stream, "UTF-8");
+		xml = XMLTools.readXMLStream(new InputStreamReader(input_stream, "UTF-8"));
+	    } catch (UnsupportedEncodingException error) {
+		System.err.println("Failed when trying to parse XML stream");
+		error.printStackTrace();
+	    }
+	    
+	    return xml;
+	}
+
+    static public StringBuffer readXMLStream(String s) {
+	return XMLTools.readXMLStream(new StringReader(s));
+    }
+
+
+    static public StringBuffer readXMLStream(Reader reader)
+	{
 		StringBuffer xml = new StringBuffer("");
 
 		try
 		{
-			InputStreamReader isr = new InputStreamReader(input_stream, "UTF-8");
-			BufferedReader buffered_in = new BufferedReader(isr);
+			BufferedReader buffered_in = new BufferedReader(reader);
 
 			String line = "";
