Ignore:
Timestamp:
2017-04-21T21:09:08+12:00 (7 years ago)
Author:
ak19
Message:

First phase of shifting gli code to use SafeProcess instead of Java Process. This phase takes care of all the easy cases.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java

    r31583 r31636  
    6060import org.greenstone.gatherer.util.GS3ServerThread;
    6161import org.greenstone.gatherer.util.JarTools;
     62import org.greenstone.gatherer.util.SafeProcess;
    6263import org.greenstone.gatherer.util.StaticStrings;
    6364import org.greenstone.gatherer.util.Utility;
     
    14331434
    14341435   
    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 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. */
     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. */
    14361437    static private class ExternalApplication
    14371438    extends Thread {
     
    16291630            boolean found = false;
    16301631
    1631             try {
     1632           
    16321633                // run the command `/path/to/perl -S gs-magick.pl identify -version`
    16331634                ArrayList cmd_list = new ArrayList();
     
    16561657                }
    16571658                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               
    16851671                return found;
    1686             }
     1672                //return (image_magick_process.exitValue() == 0);
     1673               
    16871674        }
    16881675    }
     
    17021689        {
    17031690            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);
    17071694            }
    17081695            catch (Exception exception) {
Note: See TracChangeset for help on using the changeset viewer.