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/greenstone/Classifiers.java

    r20924 r31636  
    3737import org.greenstone.gatherer.cdm.Classifier;
    3838import org.greenstone.gatherer.remote.RemoteGreenstoneServer;
     39import org.greenstone.gatherer.util.SafeProcess;
    3940import org.greenstone.gatherer.util.StaticStrings;
    4041import org.greenstone.gatherer.util.Utility;
     
    150151        args.add(classifier.getName());
    151152
    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");
    160167        }
    161168
     
    208215        args.add("-xml");
    209216
    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");
    215230        }
    216231
Note: See TracChangeset for help on using the changeset viewer.