- Timestamp:
- 2017-04-21T21:09:08+12:00 (7 years ago)
- Location:
- main/trunk/gli/src/org/greenstone/gatherer
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java
r31583 r31636 60 60 import org.greenstone.gatherer.util.GS3ServerThread; 61 61 import org.greenstone.gatherer.util.JarTools; 62 import org.greenstone.gatherer.util.SafeProcess; 62 63 import org.greenstone.gatherer.util.StaticStrings; 63 64 import org.greenstone.gatherer.util.Utility; … … 1433 1434 1434 1435 1435 /** 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 volunt eerily 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. */1436 /** 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. */ 1436 1437 static private class ExternalApplication 1437 1438 extends Thread { … … 1629 1630 boolean found = false; 1630 1631 1631 try {1632 1632 1633 // run the command `/path/to/perl -S gs-magick.pl identify -version` 1633 1634 ArrayList cmd_list = new ArrayList(); … … 1656 1657 } 1657 1658 DebugStream.println("***** Running ImageMagickTest command: " + cmd_str); 1658 1659 Process image_magick_process = Runtime.getRuntime().exec(command_parts); 1660 image_magick_process.waitFor(); 1661 1662 //new way of detection of ImageMagick 1663 InputStreamReader isr = new InputStreamReader(image_magick_process.getInputStream()); 1664 1665 BufferedReader br = new BufferedReader(isr); 1666 // Capture the standard output stream and seach for two particular occurrences: Version and ImageMagick. 1667 1668 String line = br.readLine(); 1669 if (line != null) { 1670 String lc_line = line.toLowerCase(); 1671 if (lc_line.indexOf("version") != -1 || lc_line.indexOf("imagemagick") != -1) { 1672 //System.err.println("*** ImageMagickTest Line: " + line); 1673 found = true; 1674 } // else found var remains false 1675 } 1676 1677 // Maybe put the close in a finally (but note that it can throw and IOex too)? See 1678 // http://download.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html 1679 br.close(); 1680 return found; 1681 //return (image_magick_process.exitValue() == 0); 1682 } 1683 catch (Exception exception) { 1684 exception.printStackTrace(); 1659 System.err.println("***** Running ImageMagickTest command: " + cmd_str); 1660 1661 SafeProcess image_magick_process = new SafeProcess(command_parts); 1662 int exitValue = image_magick_process.runProcess(); // default process iostream handling 1663 //new way of detection of ImageMagick 1664 // Inspect the standard output of the process and seach for two particular occurrences: Version and ImageMagick. 1665 String output = image_magick_process.getStdOutput().toLowerCase(); 1666 if (output.indexOf("version") != -1 || output.indexOf("imagemagick") != -1) { 1667 System.err.println("*** ImageMagickTest output: " + output); 1668 found = true; 1669 } // else found var remains false 1670 1685 1671 return found; 1686 } 1672 //return (image_magick_process.exitValue() == 0); 1673 1687 1674 } 1688 1675 } … … 1702 1689 { 1703 1690 try { 1704 Process perl_process = Runtime.getRuntime().exec(command);1705 perl_process.waitFor();1706 return (perl_process.exitValue()== 0);1691 SafeProcess perl_process = new SafeProcess(command); 1692 int exitValue = perl_process.runBasicProcess(); 1693 return (exitValue == 0); 1707 1694 } 1708 1695 catch (Exception exception) { -
main/trunk/gli/src/org/greenstone/gatherer/collection/ScriptOptions.java
r20924 r31636 11 11 import org.greenstone.gatherer.util.ArrayTools; 12 12 import org.greenstone.gatherer.util.Codec; 13 import org.greenstone.gatherer.util.SafeProcess; 13 14 import org.greenstone.gatherer.util.Utility; 14 15 import org.greenstone.gatherer.util.XMLTools; … … 238 239 args[5] = lang; 239 240 240 241 241 // Create the process. 242 Runtime runtime = Runtime.getRuntime(); 243 Process process = runtime.exec(args); 244 245 242 SafeProcess process = new SafeProcess(args); 243 246 244 //for (int i=0; i<args.length; i++) { 247 245 // System.err.print(args[i] + " "); … … 249 247 //System.err.println(""); 250 248 251 252 253 document = XMLTools.parseXML(process.getErrorStream()); 249 // run the SafeProcess 250 int exitVal = process.runProcess(); 251 if(exitVal != 0) { 252 throw new Exception("*** Error running ScriptOptions process, process exited with: " 253 + exitVal); 254 } 254 255 256 // get the result and process it. 257 // We expect XML to have come out of the process std error stream. 258 String errStreamOutput = process.getStdError(); 259 ///System.err.println("*********\nScriptOptions data, got:\n" + errStreamOutput + "\n**********\n"); 260 StringReader xmlStrReader = new StringReader(errStreamOutput); 261 document = XMLTools.parseXML(xmlStrReader); 262 xmlStrReader.close(); 263 264 255 265 if (document == null) { 256 266 // command has not generated XML, script has probably failed in some way -
main/trunk/gli/src/org/greenstone/gatherer/download/ServerInfoDialog.java
r31629 r31636 15 15 import org.greenstone.gatherer.greenstone.LocalGreenstone; 16 16 import org.greenstone.gatherer.gui.*; 17 import org.greenstone.gatherer.util.SafeProcess; 17 18 import org.greenstone.gatherer.util.Utility; 18 19 … … 105 106 try { 106 107 String [] env = null; 107 Process prcs = null; 108 Runtime rt = Runtime.getRuntime(); 108 SafeProcess prcs = null; 109 109 110 110 if (Utility.isWindows()) { 111 prcs = rt.exec(command); 111 prcs = new SafeProcess(command); 112 112 } 113 113 else { … … 121 121 env[2] = "GSDLHOME=" + Configuration.gsdl_path; 122 122 env[3] = "GSDLOS=" + Gatherer.client_operating_system; 123 prcs = rt.exec(command, env);123 prcs = new SafeProcess(command, env, null); 124 124 } 125 125 else { 126 126 // Will inherit the GLI's environment, with GSDLHOME and GSDLOS set 127 prcs = rt.exec(command);127 prcs = new SafeProcess(command); 128 128 } 129 129 } 130 131 InputStreamReader isr = new InputStreamReader(prcs.getErrorStream()); 132 BufferedReader br = new BufferedReader(isr); 133 String line; 134 // Capture the standard error stream and seach for two particular occurences. 135 while ((line = br.readLine()) != null && !line.trim().equals("<<Finished>>")) { 136 137 JLabel a_label = new JLabel(line); 138 a_label.setAlignmentX(Component.LEFT_ALIGNMENT); 139 info_list_pane.add(a_label); 140 } 130 131 // special processing of Process' stderr stream: 132 // Search the process standard error stream and seach for two particular occurences. 133 int exitVal = prcs.runProcess(null, new ProcErrStreamLineByLineHandler()); 141 134 142 135 } catch (Exception ioe) { … … 146 139 } 147 140 141 private class ProcErrStreamLineByLineHandler extends SafeProcess.LineByLineHandler 142 { 143 public ProcErrStreamLineByLineHandler() { 144 super(SafeProcess.STDERR); // sets this.source 145 } 146 147 public void gotLine(String line) { 148 // Check the current line from the standard error stream and seach for two particular occurences. 149 if (!line.trim().equals("<<Finished>>")) { 150 151 JLabel a_label = new JLabel(line); 152 a_label.setAlignmentX(Component.LEFT_ALIGNMENT); 153 ServerInfoDialog.this.info_list_pane.add(a_label); 154 } 155 } 156 public void gotException(Exception e) { 157 e.printStackTrace(); 158 } 159 } 148 160 } -
main/trunk/gli/src/org/greenstone/gatherer/greenstone/Classifiers.java
r20924 r31636 37 37 import org.greenstone.gatherer.cdm.Classifier; 38 38 import org.greenstone.gatherer.remote.RemoteGreenstoneServer; 39 import org.greenstone.gatherer.util.SafeProcess; 39 40 import org.greenstone.gatherer.util.StaticStrings; 40 41 import org.greenstone.gatherer.util.Utility; … … 150 151 args.add(classifier.getName()); 151 152 152 // Run the classinfo.pl process 153 Runtime runtime = Runtime.getRuntime(); 154 Process process = runtime.exec((String[]) args.toArray(new String[] { })); 155 InputStream input_stream = process.getErrorStream(); 156 StringBuffer classinfo_xml_buffer = XMLTools.readXMLStream(input_stream); 157 if (classinfo_xml_buffer != null) { 158 classinfo_xml = classinfo_xml_buffer.toString(); 159 } 153 154 // Run the classinfo.pl process: 155 // Create the process. 156 SafeProcess process = new SafeProcess((String[]) args.toArray(new String[] { })); 157 158 // run the SafeProcess 159 int exitVal = process.runProcess(); 160 if(exitVal != 0) { 161 throw new Exception("*** Error running classify.pl loadClassifierInfo, process exited with: " 162 + exitVal); 163 } 164 // get the result: We expect XML to have come out of the process std error stream. 165 classinfo_xml = process.getStdError(); 166 ///System.err.println("*********\nClassifierInfo, got:\n" + classinfo_xml + "\n**********\n"); 160 167 } 161 168 … … 208 215 args.add("-xml"); 209 216 210 // Run the classinfo.pl process 211 Runtime runtime = Runtime.getRuntime(); 212 Process process = runtime.exec((String[]) args.toArray(new String[] { })); 213 InputStream input_stream = process.getErrorStream(); 214 xml = XMLTools.readXMLStream(input_stream); 217 // Run the classinfo.pl process: 218 // Create the process. 219 SafeProcess process = new SafeProcess((String[]) args.toArray(new String[] { })); 220 221 // run the SafeProcess 222 int exitVal = process.runProcess(); 223 if(exitVal != 0) { 224 throw new Exception("*** Error running classify.pl loadClassifiersList, process exited with: " 225 + exitVal); 226 } 227 // get the result: We expect XML to have come out of the process std error stream. 228 xml = new StringBuffer(process.getStdError()); 229 ///System.err.println("*********\nClassifierList, got:\n" + xml + "\n**********\n"); 215 230 } 216 231 -
main/trunk/gli/src/org/greenstone/gatherer/greenstone/Plugins.java
r26225 r31636 37 37 import org.greenstone.gatherer.cdm.Plugin; 38 38 import org.greenstone.gatherer.remote.RemoteGreenstoneServer; 39 import org.greenstone.gatherer.util.SafeProcess; 39 40 import org.greenstone.gatherer.util.StaticStrings; 40 41 import org.greenstone.gatherer.util.Utility; … … 160 161 args.add(Configuration.getLanguage()); 161 162 args.add(plugin.getName()); 162 // Run the pluginfo.pl process 163 Runtime runtime = Runtime.getRuntime(); 164 Process process = runtime.exec((String[]) args.toArray(new String[] { })); 165 InputStream input_stream = process.getErrorStream(); 166 StringBuffer pluginfo_xml_buffer = XMLTools.readXMLStream(input_stream); 167 if (pluginfo_xml_buffer != null) { 168 pluginfo_xml = pluginfo_xml_buffer.toString(); 169 } 163 164 // Run the pluginfo.pl process: 165 // Create the process. 166 SafeProcess process = new SafeProcess((String[]) args.toArray(new String[] { })); 167 168 // run the SafeProcess 169 int exitVal = process.runProcess(); 170 if(exitVal != 0) { 171 throw new Exception("*** Error running pluginfo.pl loadPlugInfo, process exited with: " 172 + exitVal); 173 } 174 // get the result: We expect XML to have come out of the process std error stream. 175 pluginfo_xml = process.getStdError(); 176 ///System.err.println("*********\nPluginInfo, got:\n" + pluginfo_xml + "\n**********\n"); 170 177 } 171 178 … … 230 237 args.add("-xml"); 231 238 232 // Run the pluginfo.pl process 233 Runtime runtime = Runtime.getRuntime(); 234 Process process = runtime.exec((String[]) args.toArray(new String[] { })); 235 InputStream input_stream = process.getErrorStream(); 236 xml = XMLTools.readXMLStream(input_stream); 239 // Run the pluginfo.pl process: 240 // Create the process. 241 SafeProcess process = new SafeProcess((String[]) args.toArray(new String[] { })); 242 243 // run the SafeProcess 244 int exitVal = process.runProcess(); 245 if(exitVal != 0) { 246 throw new Exception("*** Error running pluginfo.pl loadPluginsList, process exited with: " 247 + exitVal); 248 } 249 // get the result: We expect XML to have come out of the process std error stream. 250 xml = new StringBuffer(process.getStdError()); 251 ///System.err.println("*********\nPluginsList, got:\n" + xml + "\n**********\n"); 237 252 } 238 253
Note:
See TracChangeset
for help on using the changeset viewer.