- Timestamp:
- 2017-04-20T18:21:50+12:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/util/SafeProcess.java
r31594 r31615 90 90 } 91 91 92 //***************** Copied from gli's gui/FormatConversionDialog.java *************// 92 private Process doRuntimeExec() throws IOException { 93 Process prcs = null; 94 Runtime rt = Runtime.getRuntime(); 95 96 if(this.command != null) { 97 prcs = rt.exec(this.command); 98 } 99 else { // at least command_args must be set now 100 101 // http://stackoverflow.com/questions/5283444/convert-array-of-strings-into-a-string-in-java 102 ///System.err.println("SafeProcess running: " + Arrays.toString(command_args)); 103 logger.info("SafeProcess running: " + Arrays.toString(command_args)); 104 105 if(this.envp == null) { 106 prcs = rt.exec(this.command_args); 107 } else { // launch process using cmd str with env params 108 109 if(this.dir == null) { 110 ///logger.info("\twith: " + Arrays.toString(this.envp)); 111 ///System.err.println("\twith: " + Arrays.toString(this.envp)); 112 prcs = rt.exec(this.command_args, this.envp); 113 } else { 114 ///logger.info("\tfrom directory: " + this.dir); 115 ///logger.info("\twith: " + Arrays.toString(this.envp)); 116 ///System.err.println("\tfrom directory: " + this.dir); 117 ///System.err.println("\twith: " + Arrays.toString(this.envp)); 118 prcs = rt.exec(this.command_args, this.envp, this.dir); 119 } 120 } 121 } 122 123 return prcs; 124 } 125 126 127 // no reading from or writing to Process' iostreams, just exec process and wait for it to return 128 public int runBasicProcess() { 129 Process prcs = null; 130 try { 131 prcs = doRuntimeExec(); 132 this.exitValue = prcs.waitFor(); 133 134 135 } catch(IOException ioe) { 136 if(exceptionHandler != null) { 137 exceptionHandler.gotException(ioe); 138 } else { 139 logger.error("IOException: " + ioe.getMessage(), ioe); 140 //System.err.println("IOException " + ioe.getMessage()); 141 //ioe.printStackTrace(); 142 } 143 } catch(InterruptedException ie) { 144 145 if(exceptionHandler != null) { 146 exceptionHandler.gotException(ie); 147 } else { 148 logger.error("Process InterruptedException: " + ie.getMessage(), ie); 149 //System.err.println("Process InterruptedException " + ie.getMessage()); 150 ///ie.printStackTrace(); // an interrupt here is not an error, it can be a cancel action 151 } 152 153 Thread.currentThread().interrupt(); 154 } finally { 155 156 if( prcs != null ) { 157 prcs.destroy(); // see runProcess() below 158 } 159 } 160 return this.exitValue; 161 } 93 162 94 163 public int runProcess() { 95 164 return runProcess(null, null, null); // use default processing of all 3 of the process' iostreams 96 165 } 166 167 //***************** Copied from gli's gui/FormatConversionDialog.java *************// 97 168 98 169 public int runProcess(CustomProcessHandler procInHandler, … … 105 176 SafeProcess.InputStreamGobbler outputGobbler = null; 106 177 107 try { 108 109 Runtime rt = Runtime.getRuntime(); 110 111 112 if(this.command != null) { 113 prcs = rt.exec(this.command); 114 } 115 else { // at least command_args must be set now 116 117 // http://stackoverflow.com/questions/5283444/convert-array-of-strings-into-a-string-in-java 118 ///System.err.println("SafeProcess running: " + Arrays.toString(command_args)); 119 logger.info("SafeProcess running: " + Arrays.toString(command_args)); 120 121 if(this.envp == null) { 122 prcs = rt.exec(this.command_args); 123 } else { // launch process using cmd str with env params 124 125 if(this.dir == null) { 126 ///logger.info("\twith: " + Arrays.toString(this.envp)); 127 ///System.err.println("\twith: " + Arrays.toString(this.envp)); 128 prcs = rt.exec(this.command_args, this.envp); 129 } else { 130 ///logger.info("\tfrom directory: " + this.dir); 131 ///logger.info("\twith: " + Arrays.toString(this.envp)); 132 ///System.err.println("\tfrom directory: " + this.dir); 133 ///System.err.println("\twith: " + Arrays.toString(this.envp)); 134 prcs = rt.exec(this.command_args, this.envp, this.dir); 135 } 136 } 137 } 178 try { 179 prcs = doRuntimeExec(); 180 138 181 139 182 // Create the streamgobblers and set any specified handlers on them … … 166 209 } 167 210 168 211 169 212 // kick off the stream gobblers 170 213 inputGobbler.start();
Note:
See TracChangeset
for help on using the changeset viewer.