- Timestamp:
- 2017-05-08T21:18:21+12:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/admin/guiext/Command.java
r25635 r31665 12 12 import javax.swing.JTextArea; 13 13 import javax.swing.JOptionPane; 14 15 import org.greenstone.util.SafeProcess; 14 16 15 17 public class Command implements Runnable … … 57 59 58 60 File workingDirectory = new File(_parent.getParent().getParent().getExtensionDirectory()); 59 Process commandLineProc = null;61 SafeProcess commandLineProc = null; 60 62 try{ 61 63 commandLineProc = null; 64 String[] args = new String[3]; 62 65 63 66 if(System.getProperty("os.name").contains("Windows")){ 64 String[] args = new String[3];65 67 args[0] = "cmd.exe"; 66 68 args[1] = "/C"; … … 75 77 messageArea.append("\nExecuting \"" + allArgs + "\" on the command line\n"); 76 78 77 commandLineProc = Runtime.getRuntime().exec(args, null, workingDirectory);79 //commandLineProc = Runtime.getRuntime().exec(args, null, workingDirectory); 78 80 } 79 81 else{ 80 String[] args = new String[3];81 82 args[0] = "sh"; 82 83 args[1] = "-c"; … … 90 91 91 92 messageArea.append("\nExecuting \"" + allArgs + "\" on the command line\n"); 92 commandLineProc = Runtime.getRuntime().exec(args, null, workingDirectory); 93 } 94 93 //commandLineProc = Runtime.getRuntime().exec(args, null, workingDirectory); 94 } 95 96 commandLineProc = new SafeProcess(args, null, workingDirectory); 97 98 /* 95 99 BufferedReader stdInput = new BufferedReader(new InputStreamReader(commandLineProc.getInputStream())); 96 100 … … 104 108 105 109 int success = commandLineProc.waitFor(); 106 110 */ 111 112 // Replacing the above and its use of the PrinterThread inner class with SafeProcess.java: 113 SafeProcess.LineByLineHandler outLineHandler = new ProcessLineHandler(messageArea, SafeProcess.STDOUT); 114 SafeProcess.LineByLineHandler errLineHandler = new ProcessLineHandler(messageArea, SafeProcess.STDERR); 115 116 int success = commandLineProc.runProcess(outLineHandler, errLineHandler); 117 107 118 if(success != 0){ 108 119 System.err.println("Command line process \"" + command + "\" returned unsuccessfully with the value \"" + success + "\""); … … 148 159 } 149 160 161 /* 150 162 public class PrinterThread extends Thread 151 163 { … … 173 185 } 174 186 } 187 }*/ 188 189 public class ProcessLineHandler extends SafeProcess.LineByLineHandler 190 { 191 // These members need to be final in order to synchronize on them 192 private final JTextArea _messageArea; 193 194 public ProcessLineHandler(JTextArea messageArea, int src) 195 { 196 super(src); // will set this.source to STDERR or STDOUT 197 _messageArea = messageArea; 198 } 199 200 public void gotLine(String line) { // first non-null line 201 202 // messageArea needs to be synchronized, since both the process' 203 // stderr and stdout will be attempting to append to it 204 205 synchronized(_messageArea) { 206 _messageArea.append(line + "\n"); 207 _messageArea.setSelectionEnd(_messageArea.getDocument().getLength()); 208 } 209 } 210 public void gotException(Exception e) { 211 e.printStackTrace(); 212 } 213 175 214 } 176 215 }
Note:
See TracChangeset
for help on using the changeset viewer.