/** * @param cmd * @param dir * @param out * @param err * @param env * @return */ private CommandResult exec( String[] pCmd, File dir, StringWriter pOut, StringWriter pErr, String[] env) throws IOException, InterruptedException { int out = 0; String pCmdString = ArrayUtils.toString(pCmd); if (_log.isDebugEnabled()) _log.debug( "Executing '" + pCmdString + "' with Environment '" + ArrayUtils.toString(env) + "'"); StopWatch clock = new StopWatch(); clock.start(); try { process = Runtime.getRuntime().exec(pCmd, env, dir); out = handleProcess(process, pCmdString, pOut, pErr, _outputList, sig_interrupt); } finally { this.cleanUpProcess(); clock.stop(); if (_log.isInfoEnabled()) _log.info("'" + pCmd + "' completed in " + clock.getTime() + " ms"); } if (sig_interrupt.getValue() == true) { out = -9999; } CommandResult result = new CommandResult(pCmdString, out, pOut.toString(), pErr.toString()); return result; }
public CommandResult exec(String[] pCmd, File dir, Writer pOut, Writer pErr) throws IOException, InterruptedException { ProcessBuilder builder = new ProcessBuilder(); Map<String, String> env = builder.environment(); int out = 0; String pCmdString = ArrayUtils.toString(pCmd); logExec(pCmdString, env); StopWatch clock = new StopWatch(); clock.start(); try { process = Runtime.getRuntime().exec(pCmd, null, dir); out = handleProcess(process, pCmdString, pOut, pErr, _outputList, sig_interrupt); } finally { this.cleanUpProcess(); clock.stop(); if (_log.isInfoEnabled()) _log.info("'" + pCmd + "' completed in " + clock.getTime() + " ms"); } if (sig_interrupt.getValue() == true) { out = -9999; } CommandResult result = new CommandResult(pCmdString, out, pOut.toString(), pErr.toString()); return result; }
public CommandResult exec( String[] pCmd, Map<String, String> pEnv, boolean useSysEnv, Writer pOut, Writer pErr) throws IOException, InterruptedException { int out = 0; String pCmdString = ArrayUtils.toString(pCmd); ProcessBuilder builder = new ProcessBuilder(); builder.command(pCmd); Map<String, String> env = builder.environment(); if (!useSysEnv) env.clear(); for (String name : pEnv.keySet()) { env.put(name, pEnv.get(name)); } logExec(pCmdString, env); StopWatch clock = new StopWatch(); clock.start(); try { process = builder.start(); out = handleProcess(process, pCmdString, pOut, pErr, _outputList, sig_interrupt); } finally { this.cleanUpProcess(); clock.stop(); if (_log.isInfoEnabled()) _log.info("'" + pCmdString + "' completed in " + clock.getTime() + " ms"); } if (sig_interrupt.getValue() == true) { out = -9999; } CommandResult result = new CommandResult(pCmdString, out, pOut.toString(), pErr.toString()); return result; }
public void run() { boolean ok = true; char[] buf = new char[bufSize]; synchronized (this) { try { while (ok) { ok = !interrupt_sig.getValue(); if (pumpLog.isDebugEnabled()) { System.currentTimeMillis(); } int n = iIn.read(buf, 0, buf.length); if (0 > n) { pumpLog.debug("CharPump has encountered EOF"); break; } if (pumpLog.isDebugEnabled()) { System.currentTimeMillis(); } if (pumpLog.isDebugEnabled()) { System.currentTimeMillis(); } iOut.write(buf, 0, n); if (pumpLog.isDebugEnabled()) { System.currentTimeMillis(); } iOut.flush(); } iOut.flush(); } catch (Exception e) { _log.error(e); e.printStackTrace(); } finally { try { if (iIn != null) { iIn.close(); } if (iOut != null) { iOut.close(); } } catch (IOException ioe) { ioe.printStackTrace(); } notifyAll(); } } }