Changeset 22012

Show
Ignore:
Timestamp:
03.05.2010 13:46:21 (9 years ago)
Author:
sjm84
Message:

Improved the execution of command line calls

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/admin/guiext/Command.java

    r21994 r22012  
    5959    Process commandLineProc = null; 
    6060    try{ 
    61         messageArea.append("\nExecuting \"" + command + "\" on the command line\n"); 
    62         commandLineProc = Runtime.getRuntime().exec(command, null, workingDirectory); 
     61        commandLineProc = null; 
     62         
     63        if(System.getProperty("os.name").contains("Windows")){ 
     64        String[] args = new String[3]; 
     65        args[0] = "cmd.exe"; 
     66        args[1] = "/C"; 
     67        args[2] = command; 
     68 
     69        String allArgs = new String(); 
     70        for(int i = 0; i < args.length; i++){ 
     71            if(i != 0){allArgs += " ";} 
     72            allArgs += args[i]; 
     73        } 
     74 
     75        messageArea.append("\nExecuting \"" + allArgs + "\" on the command line\n"); 
     76 
     77        commandLineProc = Runtime.getRuntime().exec(args, null, workingDirectory); 
     78        } 
     79        else{ 
     80        String[] args = new String[3]; 
     81        args[0] = "sh"; 
     82        args[1] = "-c"; 
     83        args[2] = command; 
     84 
     85        String allArgs = new String(); 
     86        for(int i = 0; i < args.length; i++){ 
     87            if(i != 0){allArgs += " ";} 
     88            allArgs += args[i]; 
     89        } 
     90 
     91        messageArea.append("\nExecuting \"" + allArgs + "\" on the command line\n"); 
     92        commandLineProc = Runtime.getRuntime().exec(args, null, workingDirectory); 
     93        } 
    6394         
    6495        BufferedReader stdInput = new BufferedReader(new InputStreamReader(commandLineProc.getInputStream()));