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 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 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(); }
/** 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); }
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();
SteamGobbler sg = new StreamGobbler(...); sg.start(); sg.join();
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 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 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(); }
String completeComm = userdir + "\\timer.bat"; Process p = Runtime.getRuntime().exec( "cmd /c " + completeComm + " " + command + " --batch"); new Thread(new StreamGobbler("InputStream", p.getInputStream())).start(); new Thread(new StreamGobbler("ErrorStream", p.getErrorStream())).start();
SteamGobbler sg = new StreamGobbler(...); Thread th = new Thread(sg); th.start(); th.join();
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(); }
Process process = Runtime.getRuntime().exec("ldd a.so"); StreamGobbler outputGobbler = new StreamGobbler(process.getInputStream()); outputGobbler.start(); process.waitFor(); String result = outputGobbler.buffer;
public class test1 { public static void main(String argv[]) throws IOException, InterruptedException { ProcessBuilder pb = new ProcessBuilder("cmd.exe", "/c", "convert"); pb.redirectErrorStream(true); Process p = pb.start(); StreamGobbler g = new StreamGobbler(p.getInputStream(), "OUT"); g.start(); p.waitFor(); } }
public static InputStream getBZip2PipedInputStream(String filename) throws IOException { String bzcat = System.getProperty("bzcat", "bzcat"); Runtime rt = Runtime.getRuntime(); String cmd = bzcat + " " + filename; //System.err.println("getBZip2PipedInputStream: Running command: "+cmd); Process p = rt.exec(cmd); Writer errWriter = new BufferedWriter(new OutputStreamWriter(System.err)); StreamGobbler errGobler = new StreamGobbler(p.getErrorStream(), errWriter); errGobler.start(); return p.getInputStream(); }
public static InputStream getBZip2PipedInputStream(String filename) throws IOException { String bzcat = System.getProperty("bzcat", "bzcat"); Runtime rt = Runtime.getRuntime(); String cmd = bzcat + " " + filename; //System.err.println("getBZip2PipedInputStream: Running command: "+cmd); Process p = rt.exec(cmd); Writer errWriter = new BufferedWriter(new OutputStreamWriter(System.err)); StreamGobbler errGobler = new StreamGobbler(p.getErrorStream(), errWriter); errGobler.start(); return p.getInputStream(); }
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 executarCortebi(File file){ try { Process pc = Runtime.getRuntime().exec("cmd /c start cortebi.exe",null, file); StreamGobbler error = new StreamGobbler(pc.getErrorStream(), "ERRO"); StreamGobbler output = new StreamGobbler(pc.getInputStream(), "OUTPUT"); error.start(); output.start(); pc.waitFor(); Thread.sleep(800); } catch (IOException e) { e.printStackTrace(); }catch(InterruptedException e) { e.printStackTrace(); } }
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()); }
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(); }