Changeset 24709


Ignore:
Timestamp:
2011-10-03T15:48:21+13:00 (13 years ago)
Author:
ak19
Message:

If on Windows and using the Start command to launch a file from GLI using its file association command, there may be spaces in the file path. In that case, need to launch the command slightly differently because the arguments to running a Java Process in this case are passed in as array. In this case, the start and its own arguments are all to be one element of that array.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/gli/src/org/greenstone/gatherer/file/FileAssociationManager.java

    r24707 r24709  
    162162    }
    163163   
    164     public String [] getCommand(File file) {
     164    public String [] getCommand(File file) {   
    165165    String command = null;
    166166    String [] commands = null;
     
    218218        }
    219219
    220         if (command != null && !command.equals("")) {
     220        if (command != null && !command.equals("")) {       
     221       
    221222        // Make the command into a string []       
    222223        commands = command.split(" ");
     
    228229        // We have to fix filename under windows to escape the backslashes
    229230        filename = filename.replaceAll(ESCAPE, ESCAPED_ESCAPE);
     231       
     232        // dealing with spaces in filepath when using start command
     233        if(Utility.isWindows() && filename.indexOf(" ") != -1 && command.indexOf("start") != -1) {
     234            // On Windows, start command used spaces in filepath. In this case:
     235            // start and its arguments all together need to go into one element of the commands array
     236            // otherwise <cmd /c start "window title" "%1"> does not work if there are spaces in the
     237            // file path %1, when running the Process with a command array.
     238           
     239            // Need <"start \"window\" \"%1\""> to be an element in the command array:
     240            String[] tmp = commands;
     241            int index = 0;
     242           
     243            for(int i = 0; i < commands.length; i++) {
     244                if(commands[i].indexOf("start") != -1) {
     245                    index = i;
     246                }
     247            }
     248           
     249            commands = new String[index+1];
     250            for(int i = 0; i < index; i++) {
     251                commands[i] = tmp[i];
     252            }
     253           
     254            commands[index] = tmp[index];
     255            for(int i = index+1; i < tmp.length; i++) {
     256                commands[index] = commands[index] + " " + tmp[i];
     257            }
     258           
     259        }
    230260
    231261        for (int i=0; i<commands.length; i++) {
Note: See TracChangeset for help on using the changeset viewer.