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/download/ServerInfoDialog.java

    r31629 r31636  
    1515import org.greenstone.gatherer.greenstone.LocalGreenstone;
    1616import org.greenstone.gatherer.gui.*;
     17import org.greenstone.gatherer.util.SafeProcess;
    1718import org.greenstone.gatherer.util.Utility;
    1819
     
    105106    try {
    106107        String [] env = null;
    107         Process prcs = null;
    108         Runtime rt = Runtime.getRuntime();
     108        SafeProcess prcs = null;
    109109     
    110110        if (Utility.isWindows()) {
    111                 prcs = rt.exec(command);   
     111        prcs = new SafeProcess(command);
    112112        }
    113113        else {
     
    121121            env[2] = "GSDLHOME=" + Configuration.gsdl_path;
    122122            env[3] = "GSDLOS=" + Gatherer.client_operating_system;
    123             prcs = rt.exec(command, env);
     123            prcs = new SafeProcess(command, env, null);
    124124        }
    125125        else {
    126126            // Will inherit the GLI's environment, with GSDLHOME and GSDLOS set
    127             prcs = rt.exec(command);
     127            prcs = new SafeProcess(command);
    128128        }
    129129        }
    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());
    141134       
    142135    } catch (Exception ioe) {
     
    146139    }
    147140
     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    }
    148160}
Note: See TracChangeset for help on using the changeset viewer.