1 17 18 19 20 package org.apache.fop.visual; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 25 import org.apache.commons.logging.Log; 26 27 30 public class ConvertUtils { 31 32 42 public static void convert(String cmd, String [] envp, File workDir, final Log log) 43 throws IOException { 44 log.debug(cmd); 45 46 Process process = null; 47 try { 48 process = Runtime.getRuntime().exec(cmd, envp, null); 49 50 RedirectorLineHandler errorHandler = new AbstractRedirectorLineHandler() { 52 public void handleLine(String line) { 53 log.error("ERR> " + line); 54 } 55 }; 56 StreamRedirector errorRedirector 57 = new StreamRedirector(process.getErrorStream(), errorHandler); 58 59 RedirectorLineHandler outputHandler = new AbstractRedirectorLineHandler() { 61 public void handleLine(String line) { 62 log.debug("OUT> " + line); 63 } 64 }; 65 StreamRedirector outputRedirector 66 = new StreamRedirector(process.getInputStream(), outputHandler); 67 new Thread (errorRedirector).start(); 68 new Thread (outputRedirector).start(); 69 70 process.waitFor(); 71 } catch (java.lang.InterruptedException ie) { 72 throw new IOException ("The call to the external converter failed: " + ie.getMessage()); 73 } catch (java.io.IOException ioe) { 74 throw new IOException ("The call to the external converter failed: " + ioe.getMessage()); 75 } 76 77 int exitValue = process.exitValue(); 78 if (exitValue != 0) { 79 throw new IOException ("The call to the external converter failed. Result: " 80 + exitValue); 81 } 82 83 } 84 85 86 } 87 | Popular Tags |