Changeset 15125


Ignore:
Timestamp:
2008-03-25T19:49:33+13:00 (16 years ago)
Author:
ak19
Message:

runLocal executes a Process with single string command in general, but when there are spaces in the path it executes with arguments

File:
1 edited

Legend:

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

    r15110 r15125  
    227227    private void runLocal(String[] args, BufferedOutputStream bos)
    228228    {
     229    boolean execArgs = false;
    229230    try {
    230231        String command = "";
    231         for(int i = 0; i < args.length; i++) {
     232        for(int i = 0; i < args.length && !execArgs; i++) {
     233        if(args[i].indexOf(' ') != -1) { // if any argument contains spaces, then we'll have to
     234           execArgs = true; // execute it with argument array rather than command item
     235        }
    232236        command = command + args[i] + " ";
    233237        }
     
    238242        Runtime rt = Runtime.getRuntime();
    239243        Process prcs = null;
    240      
    241         prcs = rt.exec(args);
    242         // If we used single argument exec, spaces in filenames or paths cause problems
    243         // I.e. better to avoid: prcs = rt.exec(command);
    244                
     244        if (Utility.isWindows() || execArgs){ // if execArgs=true, then we're on Linux and one or more arguments
     245        // contained spaces, meaning we'll have to execute it with an argument array rather than command item.
     246        // This is especially necessary if one of the args is a filepath containing spaces in the filename or path
     247        prcs = rt.exec(args);
     248        } else { // we're on Linux and none of the arguments contains any spaces,
     249        // so just execute with single string argument (command)
     250        prcs = rt.exec(command);
     251        }
     252                   
    245253        InputStreamReader eisr = new InputStreamReader( prcs.getErrorStream(), "UTF-8" );
    246254        InputStreamReader stdisr = new InputStreamReader( prcs.getInputStream(), "UTF-8"  );       
Note: See TracChangeset for help on using the changeset viewer.