Index: main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java
===================================================================
--- main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java	(revision 31630)
+++ main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java	(revision 31636)
@@ -60,4 +60,5 @@
 import org.greenstone.gatherer.util.GS3ServerThread;
 import org.greenstone.gatherer.util.JarTools;
+import org.greenstone.gatherer.util.SafeProcess;
 import org.greenstone.gatherer.util.StaticStrings;
 import org.greenstone.gatherer.util.Utility;
@@ -1433,5 +1434,5 @@
 
 	
-	/** This private class contains an instance of an external application running within a JVM shell. It is important that this process sits in its own thread, but its more important that when we exit the Gatherer we don't actually System.exit(0) the Gatherer object until the user has volunteerily ended all of these child processes. Otherwise when we quit the Gatherer any changes the users may have made in external programs will be lost and the child processes are automatically deallocated. */
+	/** This private class contains an instance of an external application running within a JVM shell. It is important that this process sits in its own thread, but its more important that when we exit the Gatherer we don't actually System.exit(0) the Gatherer object until the user has voluntarily ended all of these child processes. Otherwise when we quit the Gatherer any changes the users may have made in external programs will be lost and the child processes are automatically deallocated. */
 	static private class ExternalApplication
 	extends Thread {
@@ -1629,5 +1630,5 @@
 		    boolean found = false;
 
-			try {
+		    
 			    // run the command `/path/to/perl -S gs-magick.pl identify -version`
 			    ArrayList cmd_list = new ArrayList();
@@ -1656,33 +1657,19 @@
 			    }
 			    DebugStream.println("***** Running ImageMagickTest command: " + cmd_str);
-
-				Process image_magick_process = Runtime.getRuntime().exec(command_parts);
-				image_magick_process.waitFor();
-
-				//new way of detection of ImageMagick
-				InputStreamReader isr = new InputStreamReader(image_magick_process.getInputStream());
-
-				BufferedReader br = new BufferedReader(isr);
-				// Capture the standard output stream and seach for two particular occurrences: Version and ImageMagick.
-
-				String line = br.readLine();
-				if (line != null) {
-				    String lc_line = line.toLowerCase();
-				    if (lc_line.indexOf("version") != -1 || lc_line.indexOf("imagemagick") != -1) {
-					//System.err.println("*** ImageMagickTest Line: " + line);
-					found = true;
-				    } // else found var remains false
-				}
-
-				// Maybe put the close in a finally (but note that it can throw and IOex too)? See
-				// http://download.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html
-				br.close();
-				return found;
-				//return (image_magick_process.exitValue() == 0);
-			}
-			catch (Exception exception) {	
-			    exception.printStackTrace();
+			    System.err.println("***** Running ImageMagickTest command: " + cmd_str);
+			   
+			    SafeProcess image_magick_process = new SafeProcess(command_parts);
+			    int exitValue = image_magick_process.runProcess(); // default process iostream handling
+			    //new way of detection of ImageMagick
+			    // Inspect the standard output of the process and seach for two particular occurrences: Version and ImageMagick.
+			    String output = image_magick_process.getStdOutput().toLowerCase();
+			    if (output.indexOf("version") != -1 || output.indexOf("imagemagick") != -1) {
+				System.err.println("*** ImageMagickTest output: " + output);
+				found = true;
+			    } // else found var remains false	
+			    
 			    return found;
-			}
+			    //return (image_magick_process.exitValue() == 0);
+			    
 		}
 	}
@@ -1702,7 +1689,7 @@
 		{
 			try {
-				Process perl_process = Runtime.getRuntime().exec(command);
-				perl_process.waitFor();
-				return (perl_process.exitValue() == 0);
+			    SafeProcess perl_process = new SafeProcess(command);
+			    int exitValue = perl_process.runBasicProcess();
+			    return (exitValue == 0);
 			}
 			catch (Exception exception) {
Index: main/trunk/gli/src/org/greenstone/gatherer/collection/ScriptOptions.java
===================================================================
--- main/trunk/gli/src/org/greenstone/gatherer/collection/ScriptOptions.java	(revision 31630)
+++ main/trunk/gli/src/org/greenstone/gatherer/collection/ScriptOptions.java	(revision 31636)
@@ -11,4 +11,5 @@
 import org.greenstone.gatherer.util.ArrayTools;
 import org.greenstone.gatherer.util.Codec;
+import org.greenstone.gatherer.util.SafeProcess;
 import org.greenstone.gatherer.util.Utility;
 import org.greenstone.gatherer.util.XMLTools;
@@ -238,10 +239,7 @@
 		args[5] = lang;
 
-
 		// Create the process.
-		Runtime runtime = Runtime.getRuntime();
-		Process process = runtime.exec(args);
-
-		
+		SafeProcess process = new SafeProcess(args);
+
 		//for (int i=0; i<args.length; i++) { 
 		//   System.err.print(args[i] + " ");
@@ -249,8 +247,20 @@
 		//System.err.println("");
 		
-
-
-		document = XMLTools.parseXML(process.getErrorStream());
+		// run the SafeProcess
+		int exitVal = process.runProcess();
+		if(exitVal != 0) {
+		    throw new Exception("*** Error running ScriptOptions process, process exited with: "
+					+ exitVal);
+		}		
 		
+		// get the result and process it.
+		// We expect XML to have come out of the process std error stream.
+		String errStreamOutput = process.getStdError();
+		///System.err.println("*********\nScriptOptions data, got:\n" + errStreamOutput + "\n**********\n");
+		StringReader xmlStrReader = new StringReader(errStreamOutput);
+		document = XMLTools.parseXML(xmlStrReader);
+		xmlStrReader.close();
+
+
 		if (document == null) {
 		    // command has not generated XML, script has probably failed in some way
Index: main/trunk/gli/src/org/greenstone/gatherer/download/ServerInfoDialog.java
===================================================================
--- main/trunk/gli/src/org/greenstone/gatherer/download/ServerInfoDialog.java	(revision 31630)
+++ main/trunk/gli/src/org/greenstone/gatherer/download/ServerInfoDialog.java	(revision 31636)
@@ -15,4 +15,5 @@
 import org.greenstone.gatherer.greenstone.LocalGreenstone;
 import org.greenstone.gatherer.gui.*;
+import org.greenstone.gatherer.util.SafeProcess;
 import org.greenstone.gatherer.util.Utility;
 
@@ -105,9 +106,8 @@
 	try {
 	    String [] env = null;
-	    Process prcs = null; 
-	    Runtime rt = Runtime.getRuntime();
+	    SafeProcess prcs = null; 
 	  
 	    if (Utility.isWindows()) {
-              	prcs = rt.exec(command);   
+		prcs = new SafeProcess(command);
 	    }
 	    else {
@@ -121,22 +121,15 @@
 		    env[2] = "GSDLHOME=" + Configuration.gsdl_path;
 		    env[3] = "GSDLOS=" + Gatherer.client_operating_system;
-		    prcs = rt.exec(command, env); 
+		    prcs = new SafeProcess(command, env, null);
 		} 
 		else {
 		    // Will inherit the GLI's environment, with GSDLHOME and GSDLOS set
-		    prcs = rt.exec(command);
+		    prcs = new SafeProcess(command);
 		}
 	    }
-
-	    InputStreamReader isr = new InputStreamReader(prcs.getErrorStream());
-	    BufferedReader br = new BufferedReader(isr);
-	    String line;
-	    // Capture the standard error stream and seach for two particular occurences.
-	    while ((line = br.readLine()) != null && !line.trim().equals("<<Finished>>")) {
-	      
-		JLabel a_label = new JLabel(line);
-		a_label.setAlignmentX(Component.LEFT_ALIGNMENT);
-		info_list_pane.add(a_label);
-	    }
+	    
+	    // special processing of Process' stderr stream: 
+	    // Search the process standard error stream and seach for two particular occurences.
+	    int exitVal = prcs.runProcess(null, new ProcErrStreamLineByLineHandler());
 	    
 	} catch (Exception ioe) {
@@ -146,3 +139,22 @@
     }
 
+    private class ProcErrStreamLineByLineHandler extends SafeProcess.LineByLineHandler
+    {
+	public ProcErrStreamLineByLineHandler() {
+	    super(SafeProcess.STDERR); // sets this.source
+	}
+
+	public void gotLine(String line) {
+	    // Check the current line from the standard error stream and seach for two particular occurences.
+	    if (!line.trim().equals("<<Finished>>")) {
+	      
+		JLabel a_label = new JLabel(line);
+		a_label.setAlignmentX(Component.LEFT_ALIGNMENT);
+		ServerInfoDialog.this.info_list_pane.add(a_label);
+	    }
+	}
+	public void gotException(Exception e) {
+	    e.printStackTrace();
+	}
+    }
 }
Index: main/trunk/gli/src/org/greenstone/gatherer/greenstone/Classifiers.java
===================================================================
--- main/trunk/gli/src/org/greenstone/gatherer/greenstone/Classifiers.java	(revision 31630)
+++ main/trunk/gli/src/org/greenstone/gatherer/greenstone/Classifiers.java	(revision 31636)
@@ -37,4 +37,5 @@
 import org.greenstone.gatherer.cdm.Classifier;
 import org.greenstone.gatherer.remote.RemoteGreenstoneServer;
+import org.greenstone.gatherer.util.SafeProcess;
 import org.greenstone.gatherer.util.StaticStrings;
 import org.greenstone.gatherer.util.Utility;
@@ -150,12 +151,18 @@
 		args.add(classifier.getName());
 
-		// Run the classinfo.pl process
-		Runtime runtime = Runtime.getRuntime();
-		Process process = runtime.exec((String[]) args.toArray(new String[] { }));
-		InputStream input_stream = process.getErrorStream();
-		StringBuffer classinfo_xml_buffer = XMLTools.readXMLStream(input_stream);
-		if (classinfo_xml_buffer != null) {
-		    classinfo_xml = classinfo_xml_buffer.toString();
-		}
+
+		// Run the classinfo.pl process:
+		// Create the process.
+		SafeProcess process = new SafeProcess((String[]) args.toArray(new String[] { }));
+
+		// run the SafeProcess
+		int exitVal = process.runProcess();
+		if(exitVal != 0) {
+		    throw new Exception("*** Error running classify.pl loadClassifierInfo, process exited with: "
+					+ exitVal);
+		}
+		// get the result: We expect XML to have come out of the process std error stream.
+		classinfo_xml = process.getStdError();
+		///System.err.println("*********\nClassifierInfo, got:\n" + classinfo_xml + "\n**********\n");
 	    }
 
@@ -208,9 +215,17 @@
 		args.add("-xml");
 
-		// Run the classinfo.pl process
-		Runtime runtime = Runtime.getRuntime();
-		Process process = runtime.exec((String[]) args.toArray(new String[] { }));
-		InputStream input_stream = process.getErrorStream();
-		xml = XMLTools.readXMLStream(input_stream);
+		// Run the classinfo.pl process:
+		// Create the process.
+		SafeProcess process = new SafeProcess((String[]) args.toArray(new String[] { }));
+
+		// run the SafeProcess
+		int exitVal = process.runProcess();
+		if(exitVal != 0) {
+		    throw new Exception("*** Error running classify.pl loadClassifiersList, process exited with: "
+					+ exitVal);
+		}
+		// get the result: We expect XML to have come out of the process std error stream.
+		xml = new StringBuffer(process.getStdError());
+		///System.err.println("*********\nClassifierList, got:\n" + xml + "\n**********\n");
 	    }
 
Index: main/trunk/gli/src/org/greenstone/gatherer/greenstone/Plugins.java
===================================================================
--- main/trunk/gli/src/org/greenstone/gatherer/greenstone/Plugins.java	(revision 31630)
+++ main/trunk/gli/src/org/greenstone/gatherer/greenstone/Plugins.java	(revision 31636)
@@ -37,4 +37,5 @@
 import org.greenstone.gatherer.cdm.Plugin;
 import org.greenstone.gatherer.remote.RemoteGreenstoneServer;
+import org.greenstone.gatherer.util.SafeProcess;
 import org.greenstone.gatherer.util.StaticStrings;
 import org.greenstone.gatherer.util.Utility;
@@ -160,12 +161,18 @@
 		args.add(Configuration.getLanguage());
 		args.add(plugin.getName());
-		// Run the pluginfo.pl process
-		Runtime runtime = Runtime.getRuntime();
-		Process process = runtime.exec((String[]) args.toArray(new String[] { }));
-		InputStream input_stream = process.getErrorStream();
-		StringBuffer pluginfo_xml_buffer = XMLTools.readXMLStream(input_stream);
-		if (pluginfo_xml_buffer != null) {
-		    pluginfo_xml = pluginfo_xml_buffer.toString();
-		}
+
+		// Run the pluginfo.pl process:
+		// Create the process.
+		SafeProcess process = new SafeProcess((String[]) args.toArray(new String[] { }));
+
+		// run the SafeProcess
+		int exitVal = process.runProcess();
+		if(exitVal != 0) {
+		    throw new Exception("*** Error running pluginfo.pl loadPlugInfo, process exited with: "
+					+ exitVal);
+		}
+		// get the result: We expect XML to have come out of the process std error stream.
+		pluginfo_xml = process.getStdError();
+		///System.err.println("*********\nPluginInfo, got:\n" + pluginfo_xml + "\n**********\n");
 	    }
 
@@ -230,9 +237,17 @@
 		args.add("-xml");
 
-		// Run the pluginfo.pl process
-		Runtime runtime = Runtime.getRuntime();
-		Process process = runtime.exec((String[]) args.toArray(new String[] { }));
-		InputStream input_stream = process.getErrorStream();
-		xml = XMLTools.readXMLStream(input_stream);
+		// Run the pluginfo.pl process:
+		// Create the process.
+		SafeProcess process = new SafeProcess((String[]) args.toArray(new String[] { }));
+
+		// run the SafeProcess
+		int exitVal = process.runProcess();
+		if(exitVal != 0) {
+		    throw new Exception("*** Error running pluginfo.pl loadPluginsList, process exited with: "
+					+ exitVal);
+		}
+		// get the result: We expect XML to have come out of the process std error stream.
+		xml = new StringBuffer(process.getStdError());
+		///System.err.println("*********\nPluginsList, got:\n" + xml + "\n**********\n");
 	    }
 
