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/collection/ScriptOptions.java

    r20924 r31636  
    1111import org.greenstone.gatherer.util.ArrayTools;
    1212import org.greenstone.gatherer.util.Codec;
     13import org.greenstone.gatherer.util.SafeProcess;
    1314import org.greenstone.gatherer.util.Utility;
    1415import org.greenstone.gatherer.util.XMLTools;
     
    238239        args[5] = lang;
    239240
    240 
    241241        // Create the process.
    242         Runtime runtime = Runtime.getRuntime();
    243         Process process = runtime.exec(args);
    244 
    245        
     242        SafeProcess process = new SafeProcess(args);
     243
    246244        //for (int i=0; i<args.length; i++) {
    247245        //   System.err.print(args[i] + " ");
     
    249247        //System.err.println("");
    250248       
    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        }       
    254255       
     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
    255265        if (document == null) {
    256266            // command has not generated XML, script has probably failed in some way
Note: See TracChangeset for help on using the changeset viewer.