response.append(isr.getResult());
if (isr.getException() != null) { log.error("input stream reader got exception,\n      "+ "command = "+ERXStringUtilities.toString(command, " ")+ "result = "+isr.getResultAsString(), isr.getException()); } if (esr.getException() != null) { log.error("error stream reader got exception,\n      "+ "command = "+ERXStringUtilities.toString(command, " ")+ "result = "+esr.getResultAsString(), esr.getException()); }
    public final static Result execute(String[] command, String[] envp,            File dir, long timeout) throws IOException, TimeoutException {        File outputFile = null;        Runtime rt = Runtime.getRuntime();        Process p = null;        int exitValue = 0;        StringBuffer response = new StringBuffer();        String input = "";        String error = "";        StreamReader isr = null;        StreamReader esr = null;        try {            if (log.isDebugEnabled()) {                log.debug("will execute command " + command);            }            if (dir == null && envp == null) {                p = rt.exec(command);            } else if (dir == null) {                p = rt.exec(command, envp);            } else if (envp == null) {                throw new IllegalArgumentException(                        "if dir != null then envp must also be != null");            } else {                p = rt.exec(command, envp, dir);            }            // DT: we must read from input and error stream in separate threads            // because if the buffer from these streams are full the process            // will block!            isr = new StreamReader(p.getInputStream());            esr = new StreamReader(p.getErrorStream());            if (timeout > 0) {                final Process pp = p;                TimeoutTimerTask task = new TimeoutTimerTask(p);                Timer timer = new Timer();                timer.schedule(task, timeout);                try {                    p.waitFor();                } catch (InterruptedException ex) {                }                timer.cancel();                if (task.hasTimeout()) {                    throw new TimeoutException("process did't exit after "                            + timeout + " milliseconds");                }            } else {                // wait for the result of the process                try {                    p.waitFor();                } catch (InterruptedException ex) {                }            }            response.append(isr.getResult());        } finally {            try {                freeProcessResources(p);            } catch (NullPointerException e) {                // p was null            }            if (outputFile != null)                outputFile.delete();        }        return new Result(isr.getResult(), esr.getResult());    }