public static InputStream getBZip2PipedInputStream(String filename) throws IOException { String bzcat = System.getProperty("bzcat", "bzcat"); Runtime rt = Runtime.getRuntime(); String cmd = bzcat + " " + filename; //log.info("getBZip2PipedInputStream: Running command: "+cmd); Process p = rt.exec(cmd); Writer errWriter = new BufferedWriter(new OutputStreamWriter(System.err)); StreamGobbler errGobbler = new StreamGobbler(p.getErrorStream(), errWriter); errGobbler.start(); return p.getInputStream(); }
public void close() throws IOException { process.getOutputStream().close(); try { outGobbler.join(); errGobbler.join(); outGobbler.getOutputStream().close(); process.waitFor(); } catch (InterruptedException ex) { throw new RuntimeInterruptedException(ex); } //log.info("getBZip2PipedOutputStream: Closed. "); } }
public StreamGobbler (InputStream is, Writer outputFileHandle) { this.is = is; this.outputFileHandle = outputFileHandle; this.setDaemon(true); }
/** A straightforward constructor. */ private RunningProcess(Process process) { this.process = process; Writer errWriter = new BufferedWriter(new OutputStreamWriter(System.err)); this.stderr = new StreamGobbler(process.getErrorStream(), errWriter); this.stderr.start(); Writer outWriter = new BufferedWriter(new OutputStreamWriter(System.out)); this.stdout = new StreamGobbler(process.getErrorStream(), outWriter); this.stdout.start(); this.shutdownHoook = new Thread(() -> { log.info("Killing process " + WebServiceAnnotator.this); this.stdout.kill(); this.stderr.kill(); if (this.process.isAlive()) { this.process.destroy(); } this.ready = false; }); Runtime.getRuntime().addShutdownHook(this.shutdownHoook); }
public ProcessOutputStream(ProcessBuilder builder, Writer output, Writer error) throws IOException { this.process = builder.start(); errWriterThread = new StreamGobbler(process.getErrorStream(), error); outWriterThread = new StreamGobbler(process.getInputStream(), output); errWriterThread.start(); outWriterThread.start(); }
if (waitForResult) StreamGobbler errordataReader = new StreamGobbler(process .getErrorStream(), "ERROR"); StreamGobbler outputdataReader = new StreamGobbler(process .getInputStream(), "OUTPUT"); errordataReader.start(); outputdataReader.start(); errordataReader.join(); outputdataReader.join(); result.returnCode = exitVal; result.output = outputdataReader.output;
public static String runProcess(String executable, String parameter) { try { String path = String.format("%s %s", executable, parameter); Process pr = Runtime.getRuntime().exec(path); StreamGobbler errorGobbler = new StreamGobbler(pr.getErrorStream()); StreamGobbler outputGobbler = new StreamGobbler(pr.getInputStream()); // kick them off concurrently errorGobbler.start(); outputGobbler.start(); pr.waitFor(); return outputGobbler.getOutput(); } catch (Exception e) { return null; } }
Process proc = Runtime.getRuntime().exec(cmd) // Start a stream gobbler to read the error stream. StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream()); errorGobbler.start(); OutputStreamWriter osw = new OutputStreamWriter(proc.getOutputStream()) osw.write(mailBody) osw.close(); int exitStatus = proc.waitFor(); if (0 != exitStatus) { /* * If you had not used a StreamGobbler to read the errorStream, you wouldn't have * had a chance to know what went wrong with this command execution. */ LOG.warn("Error while sending email: " + errorGobbler.getContent()); }
StreamGobbler outputGobbler = new StreamGobbler(process.getInputStream(), "OUTPUT", printOutput); StreamGobbler errorGobbler = new StreamGobbler(process.getErrorStream(), "ERROR", printError); outputGobbler.start(); errorGobbler.start(); StreamGobbler outputGobbler = new StreamGobbler(process.getInputStream(), "OUTPUT", printOutput); StreamGobbler errorGobbler = new StreamGobbler(process.getErrorStream(), "ERROR", printError); outputGobbler.start(); errorGobbler.start(); StreamGobbler outputGobbler = new StreamGobbler(process.getInputStream(), "OUTPUT", printOutput); StreamGobbler errorGobbler = new StreamGobbler(process.getErrorStream(), "ERROR", printError); outputGobbler.start(); errorGobbler.start();
StreamGobbler errorGobbler = new StreamGobbler(process.getErrorStream(), "ERROR"); errorGobbler.start();
public BZip2PipedOutputStream(String filename, OutputStream err) throws IOException { String bzip2 = System.getProperty("bzip2", "bzip2"); String cmd = bzip2; // + " > " + filename; //log.info("getBZip2PipedOutputStream: Running command: "+cmd); ProcessBuilder pb = new ProcessBuilder(); pb.command(cmd); this.process = pb.start(); this.filename = filename; OutputStream outStream = new FileOutputStream(filename); errWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(err))); outGobbler = new ByteStreamGobbler("Output stream gobbler: " + cmd + " " + filename, process.getInputStream(), outStream); errGobbler = new StreamGobbler(process.getErrorStream(), errWriter); outGobbler.start(); errGobbler.start(); }
SteamGobbler sg = new StreamGobbler(...); sg.start(); sg.join();
public void close() throws IOException { process.getOutputStream().close(); try { outGobbler.join(); errGobbler.join(); outGobbler.getOutputStream().close(); process.waitFor(); } catch (InterruptedException ex) {} //System.err.println("getBZip2PipedOutputStream: Closed. "); } }
private int execProcess(String cmd, ShellCallback sc, File fileExec) throws IOException, InterruptedException { ProcessBuilder pb = new ProcessBuilder(cmd); pb.directory(fileExec); Log.d(TAG,cmd); // pb.redirectErrorStream(true); Process process = pb.start(); // any error message? StreamGobbler errorGobbler = new StreamGobbler(process.getErrorStream(), "ERROR", sc); // any output? StreamGobbler outputGobbler = new StreamGobbler(process.getInputStream(), "OUTPUT", sc); // kick them off errorGobbler.start(); outputGobbler.start(); int exitVal = process.waitFor(); sc.processComplete(exitVal); return exitVal; }
public StreamGobbler (InputStream is, Writer outputFileHandle) { this.is = is; this.outputFileHandle = outputFileHandle; this.setDaemon(true); }
Process process = Runtime.getRuntime().exec("ldd a.so"); StreamGobbler outputGobbler = new StreamGobbler(process.getInputStream()); outputGobbler.start(); process.waitFor(); String result = outputGobbler.buffer;
public ProcessOutputStream(ProcessBuilder builder, Writer output, Writer error) throws IOException { this.process = builder.start(); errWriterThread = new StreamGobbler(process.getErrorStream(), error); outWriterThread = new StreamGobbler(process.getInputStream(), output); errWriterThread.start(); outWriterThread.start(); }
public void close() throws IOException { process.getOutputStream().close(); try { outGobbler.join(); errGobbler.join(); outGobbler.getOutputStream().close(); process.waitFor(); } catch (InterruptedException ex) {} //System.err.println("getBZip2PipedOutputStream: Closed. "); } }
public StreamGobbler (InputStream is, Writer outputFileHandle) { this.is = is; this.outputFileHandle = outputFileHandle; this.setDaemon(true); }