- Timestamp:
- 2017-04-06T15:24:43+12:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/util/SafeProcess.java
r31574 r31578 97 97 //***************** Copied from gli's gui/FormatConversionDialog.java *************// 98 98 public void runProcess() { 99 99 100 Process prcs = null; 100 101 SafeProcess.OutputStreamGobbler inputGobbler = null; … … 103 104 104 105 try { 105 106 106 Runtime rt = Runtime.getRuntime(); 107 107 108 109 108 // http://stackoverflow.com/questions/5283444/convert-array-of-strings-into-a-string-in-java 110 logger.info("Running process: " + Arrays.toString(command_args));109 //logger.info("Running process: " + Arrays.toString(command_args)); 111 110 112 111 if(this.envp == null) { … … 115 114 116 115 if(this.dir == null) { 117 logger.info("\twith: " + Arrays.toString(this.envp));116 //logger.info("\twith: " + Arrays.toString(this.envp)); 118 117 prcs = rt.exec(this.command_args, this.envp); 119 118 } else { 120 logger.info("\tfrom directory: " + this.dir);121 logger.info("\twith: " + Arrays.toString(this.envp));119 //logger.info("\tfrom directory: " + this.dir); 120 //logger.info("\twith: " + Arrays.toString(this.envp)); 122 121 prcs = rt.exec(this.command_args, this.envp, this.dir); 123 122 } 124 123 } 125 124 126 logger.info("### Before creating ProcessInGobbler");127 128 129 125 // send inputStr to process. The following constructor can handle inputStr being null 130 126 inputGobbler = // WriterToProcessInputStream 131 127 new SafeProcess.OutputStreamGobbler(prcs.getOutputStream(), this.inputStr); 132 128 133 logger.info("### Before creating ProcessErrGobbler");134 135 129 // monitor for any error messages 136 130 errorGobbler // ReaderFromProcessOutputStream 137 131 = new SafeProcess.InputStreamGobbler(prcs.getErrorStream(), splitStdOutputNewLines); 138 132 139 logger.info("### Before creating ProcessOutGobbler");140 141 133 // monitor for the expected std output line(s) 142 134 outputGobbler 143 135 = new SafeProcess.InputStreamGobbler(prcs.getInputStream(), splitStdErrorNewLines); 144 145 logger.info("### Before setting handlers on ProcessGobblers");146 136 147 137 // register line by line handlers, if any were set, for the process stderr and stdout streams … … 156 146 } 157 147 158 logger.info("### Before streamgobblers.start()");159 160 148 // kick off the stream gobblers 161 149 inputGobbler.start(); 162 150 errorGobbler.start(); 163 151 outputGobbler.start(); 164 165 logger.info("### After streamgobblers.start() - before waitFor");166 152 167 153 // any error??? 168 154 this.exitValue = prcs.waitFor(); // can throw an InterruptedException if process did not terminate 169 logger.info("ExitValue: " + exitValue);170 171 logger.info("### Before streamgobblers.join()");172 173 155 // From the comments of 174 156 // http://www.javaworld.com/article/2071275/core-java/when-runtime-exec---won-t.html?page=2 … … 180 162 inputGobbler.join(); 181 163 182 logger.info("### After streamgobblers.join()");183 184 164 // set the variables the code that created a SafeProcess object may want to inspect 185 165 this.outputStr = outputGobbler.getOutput(); 186 166 this.errorStr = errorGobbler.getOutput(); 187 167 188 // the calling code should handle errorStr, not us, so can leave out the following code189 /*190 if(!this.errorStr.equals("")) {191 logger.info("*** Process errorstream: \n" + this.errorStr + "\n****");192 //System.err.println("*** Process errorstream: \n" + this.errorStr + "\n****");193 }194 */195 196 168 // Since we didn't have an exception, process should have terminated now (waitFor blocks until then) 197 169 // Set process to null so we don't forcibly terminate it below with process.destroy()
Note:
See TracChangeset
for help on using the changeset viewer.