1 17 18 19 20 package org.apache.lenya.cms.task; 21 22 23 public class CommandLineTask extends AbstractTask { 24 27 public CommandLineTask() { 28 } 29 30 36 public void execute(String path) throws ExecutionException { 37 String command = getParameters().getParameter("command", 38 "echo \"Exception: No command parameter\""); 39 40 try { 41 Process process = Runtime.getRuntime().exec(command); 42 43 java.io.InputStream in = process.getInputStream(); 44 byte[] buffer = new byte[1024]; 45 int bytes_read = 0; 46 java.io.ByteArrayOutputStream baout = new java.io.ByteArrayOutputStream (); 47 48 while ((bytes_read = in.read(buffer)) != -1) { 49 baout.write(buffer, 0, bytes_read); 50 } 51 52 if (baout.toString().length() > 0) { 53 throw new ExecutionException("%%%InputStream:S" + baout.toString() + 54 "END:InputStream%%%"); 55 } 56 57 java.io.InputStream in_e = process.getErrorStream(); 58 java.io.ByteArrayOutputStream baout_e = new java.io.ByteArrayOutputStream (); 59 60 while ((bytes_read = in_e.read(buffer)) != -1) { 61 baout_e.write(buffer, 0, bytes_read); 62 } 63 64 if (baout_e.toString().length() > 0) { 65 throw new ExecutionException("###ErrorStream:START" + baout_e.toString() + 66 "END:ErrorStream###"); 67 } 68 } catch (java.io.IOException e) { 69 throw new ExecutionException(e); 70 } 71 } 72 } 73 | Popular Tags |