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 errorGobbler = new StreamGobbler(process.getErrorStream(), "ERROR"); errorGobbler.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(); }
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; //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 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 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(); } }
try { FileOutputStream fos = new FileOutputStream("c:/test.txt"); Runtime rt = Runtime.getRuntime(); Process proc = rt.exec("mysql.exe -u root -e \"select * from table_name\" database_name"); StreamGobbler errorGobbler = new StreamGobbler( proc.getErrorStream(), "ERROR"); StreamGobbler outputGobbler = new StreamGobbler( proc.getInputStream(), "OUTPUT", fos); errorGobbler.start(); outputGobbler.start(); int exitVal = proc.waitFor(); System.out.println("ExitValue: " + exitVal); fos.flush(); fos.close(); } catch (Throwable t) { t.printStackTrace(); }
Process process = new ProcessBuilder("find", Main.serversPath, "-name", "'dynmap'").start(); StreamGobbler error = new StreamGobbler(process.getErrorStream()); error.start(); BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream())); while ((s = stdInput.readLine()) != null) { filesToDelete.add(s); if (Main.debugMode.equals("High")) { System.out.println("Preprocess: dynmap pass - found " + s); } } // Get the exit status int exitStatus = process.waitFor(); if (exitStatus != 0) { // read the error.getMessage() and handle accordingly. } process.destroy();
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 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; } }
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(); }
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(); }
public BZip2PipedOutputStream(String filename, OutputStream err) throws IOException { String bzip2 = System.getProperty("bzip2", "bzip2"); String cmd = bzip2; // + " > " + filename; //System.err.println("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(); }
public BZip2PipedOutputStream(String filename, OutputStream err) throws IOException { String bzip2 = System.getProperty("bzip2", "bzip2"); String cmd = bzip2; // + " > " + filename; //System.err.println("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(); }