Ignore:
Timestamp:
2003-12-09T12:17:56+13:00 (20 years ago)
Author:
jmt12
Message:

Added then removed debug statements

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/shell/GShell.java

    r6051 r6182  
    140140     */
    141141    /* private void removeGShellListener(GShellListener listener) {
    142     listeners.remove(GShellListener.class, listener);
    143     } */
     142       listeners.remove(GShellListener.class, listener);
     143       } */
     144
    144145    /** Any threaded class must include this method to allow the thread body to be run. */
    145     public void run() {
    146         if(progress != null) {
    147             progress.start();
    148         }
    149         // Determine if the user has asked for an outfile.
    150         String out_name = null;
    151         BufferedOutputStream bos = null;
    152         if(type == IMPORT || type == BUILD) {
    153             if(type == IMPORT) {
    154             out_name = (String) Gatherer.c_man.getCollection().build_options.getImportValue("out");
    155             }
    156             else {
    157             out_name = (String) Gatherer.c_man.getCollection().build_options.getBuildValue("out");
    158             }
    159             if(out_name != null && out_name.length() > 0) {
    160             try {
    161                 bos = new BufferedOutputStream(new FileOutputStream(new File(out_name), true));
    162             }
    163             catch (Exception error) {
    164                 Gatherer.printStackTrace(error);
    165             }
    166             }
    167         }
    168         // Issue a processBegun event
    169         fireProcessBegun(type, status);
     146    public void run() {
     147    if(progress != null) {
     148        progress.start();
     149    }
     150    // Determine if the user has asked for an outfile.
     151    String out_name = null;
     152    BufferedOutputStream bos = null;
     153    if(type == IMPORT || type == BUILD) {
     154        if(type == IMPORT) {
     155        out_name = (String) Gatherer.c_man.getCollection().build_options.getImportValue("out");
     156        }
     157        else {
     158        out_name = (String) Gatherer.c_man.getCollection().build_options.getBuildValue("out");
     159        }
     160        if(out_name != null && out_name.length() > 0) {
    170161        try {
    171 
     162            bos = new BufferedOutputStream(new FileOutputStream(new File(out_name), true));
     163        }
     164        catch (Exception error) {
     165            Gatherer.printStackTrace(error);
     166        }
     167        }
     168    }
     169    // Issue a processBegun event
     170    fireProcessBegun(type, status);
     171    try {
    172172        String command = "";
    173173        for(int i = 0; i < args.length; i++) {
     
    176176        ///ystem.err.println("Command: " + command);
    177177        fireMessage(type, Dictionary.get("GShell.Command") + ": " + command, status);
    178 
     178       
    179179        Runtime rt = Runtime.getRuntime();
    180180        Process prcs = rt.exec(args);
     
    184184        //BufferedReader stdinbr = new BufferedReader( stdinisr );
    185185        // Captures the std err of a program and pipes it into std in of java
    186 
     186       
    187187        StringBuffer eline_buffer = new StringBuffer();
    188188        StringBuffer stdline_buffer = new StringBuffer();
     
    241241        }
    242242        }
    243 
    244             // Of course, just because the process is finished doesn't mean the incoming streams are empty. Unfortunately I've got no chance of preserving order, so I'll process the error stream first, then the out stream
    245             while(eisr.ready()) {
    246                 int c = eisr.read();
    247                 ///atherer.println("eisr: '" + (char) c + "'");
    248                 if(c == '\n' || c == '\r') {
    249                     if(eline_buffer.length() > 0) {
    250                         String eline = eline_buffer.toString();
    251                         ///atherer.println("* " + eline + " *");
    252                         if(progress != null) {
    253                             progress.parse(eline);
    254                         }
    255                         if(bos != null) {
    256                             try {
    257                                 bos.write(eline.getBytes(), 0, eline.length());
    258                             }
    259                             catch(Exception error) {
    260                                 Gatherer.printStackTrace(error);
    261                             }
    262                         }
    263                         fireMessage(type, typeAsString(type) + "> " + eline, status);
    264                         eline = null;
    265                         eline_buffer = new StringBuffer();
    266                     }
    267                 }
    268                 else {
    269                     eline_buffer.append((char)c);
    270                 }
    271             }
    272             while(stdisr.ready()) {
    273                 int c = stdisr.read();
    274                 ///atherer.println("eisr: '" + (char) c + "'");
    275                 if(c == '\n' || c == '\r') {
    276                     if(stdline_buffer.length() > 0) {
    277                         String stdline = stdline_buffer.toString();
    278                         ///atherer.println("+ " + stdline + " +");
    279                         fireMessage(type, typeAsString(type) + "> " + stdline, status);
    280                         stdline = null;
    281                         stdline_buffer = new StringBuffer();
    282                     }
    283                 }
    284                 else {
    285                     stdline_buffer.append((char)c);
    286                 }
    287             }
    288 
    289         // Ensure that any messages still remaining in the string buffers are fired off.
    290         if(eline_buffer.length() > 0) {
     243       
     244        // Of course, just because the process is finished doesn't mean the incoming streams are empty. Unfortunately I've got no chance of preserving order, so I'll process the error stream first, then the out stream
     245        while(eisr.ready()) {
     246        int c = eisr.read();
     247        ///atherer.println("eisr: '" + (char) c + "'");
     248        if(c == '\n' || c == '\r') {
     249            if(eline_buffer.length() > 0) {
    291250            String eline = eline_buffer.toString();
     251            ///atherer.println("* " + eline + " *");
    292252            if(progress != null) {
    293                 progress.parse(eline);
     253                progress.parse(eline);
    294254            }
    295255            if(bos != null) {
    296                 try {
    297                     bos.write(eline.getBytes(), 0, eline.length());
    298                 }
    299                 catch(Exception error) {
    300                     Gatherer.printStackTrace(error);
    301                 }
     256                try {
     257                bos.write(eline.getBytes(), 0, eline.length());
     258                }
     259                catch(Exception error) {
     260                Gatherer.printStackTrace(error);
     261                }
    302262            }
    303263            fireMessage(type, typeAsString(type) + "> " + eline, status);
    304264            eline = null;
    305         }
    306 
    307         if(stdline_buffer.length() > 0) {
     265            eline_buffer = new StringBuffer();
     266            }
     267        }
     268        else {
     269            eline_buffer.append((char)c);
     270        }
     271        }
     272        while(stdisr.ready()) {
     273        int c = stdisr.read();
     274        ///atherer.println("eisr: '" + (char) c + "'");
     275        if(c == '\n' || c == '\r') {
     276            if(stdline_buffer.length() > 0) {
    308277            String stdline = stdline_buffer.toString();
     278            ///atherer.println("+ " + stdline + " +");
    309279            fireMessage(type, typeAsString(type) + "> " + stdline, status);
    310280            stdline = null;
    311         }
    312 
     281            stdline_buffer = new StringBuffer();
     282            }
     283        }
     284        else {
     285            stdline_buffer.append((char)c);
     286        }
     287        }
     288       
     289        // Ensure that any messages still remaining in the string buffers are fired off.
     290        if(eline_buffer.length() > 0) {
     291        String eline = eline_buffer.toString();
     292        ///atherer.println("Last bit of eline: " + eline);
     293        if(progress != null) {
     294            progress.parse(eline);
     295        }
     296        if(bos != null) {
     297            try {
     298            bos.write(eline.getBytes(), 0, eline.length());
     299            }
     300            catch(Exception error) {
     301            Gatherer.printStackTrace(error);
     302            }
     303        }
     304        fireMessage(type, typeAsString(type) + "> " + eline, status);
     305        eline = null;
     306        }
     307       
     308        if(stdline_buffer.length() > 0) {
     309        String stdline = stdline_buffer.toString();
     310        ///atherer.println("Last bit of stdline: " + stdline);
     311        fireMessage(type, typeAsString(type) + "> " + stdline, status);
     312        stdline = null;
     313        }
     314       
    313315        if(!hasSignalledStop()) {
    314316        // Now display final message based on exit value
    315317        prcs.waitFor();
    316 
     318       
    317319        if(prcs.exitValue() == 0) {
    318320            status = OK;
Note: See TracChangeset for help on using the changeset viewer.