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

GS3 source code now updated to use SafeProcess instead of Process (calling Runtime.exec() directly). The use of SafeProcess in RunTarget and BrowserLauncher has been tested on Linux. GDBMWrapper, MapRetrieve and admin/guiext's Command.java are not tested. For GDBMWrapper, because it's in a bit of code that works with txtgz databases. MapRetrive.java and Command.java are untested because I don't know how to test them.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/util/RunTarget.java

    r29946 r31665  
    33import java.io.IOException;
    44import java.io.BufferedReader;
     5import java.io.Closeable;
    56import java.io.InputStream;
    67import java.io.InputStreamReader;
     
    2829     try {
    2930         state = -1;
    30          Runtime run = Runtime.getRuntime();
    31 
    3231         String targetCmd = getTargetCmd();
    3332         logger.info("Target: " + targetCmd);
    3433
     34         /*
     35         Runtime run = Runtime.getRuntime();
    3536             Process process = run.exec(targetCmd);
    3637         BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
     
    5556         
    5657         br.close();
     58         */
     59         
     60         
     61         SafeProcess process = new SafeProcess(targetCmd);
     62         process.setSplitStdOutputNewLines(true);
     63         process.runProcess();       
     64         String output = process.getStdOutput();
     65         String[] lines = output.split("[\\r\\n]+"); // http://stackoverflow.com/questions/454908/split-java-string-by-new-line
     66         for(int i = 0; i < lines.length; i++) {
     67         //System.err.println("*** Got line:|" + lines[i] + "|***");
     68         String line = lines[i].trim();
     69         if (line.equals(targetSuccess)){
     70             state = 0;
     71         }
     72         
     73         if (line.equals(targetFailed)){
     74             state = 1;
     75         }
    5776
     77         if(line.startsWith(targetFinished)){
     78             break;     
     79         }
     80         }
     81         //System.err.println("\n\n");
     82
     83         
    5884         if(state < 0) {
    5985         logger.info("Unexpected end of input when running target: " + targetCmd);
Note: See TracChangeset for help on using the changeset viewer.