List of usage examples for org.apache.commons.exec PumpStreamHandler PumpStreamHandler
public PumpStreamHandler(final OutputStream outAndErr)
PumpStreamHandler
. From source file:ro.cosu.vampires.client.executors.fork.ForkExecutor.java
private boolean isNumaEnabled() { int exitCode; try {/*from w w w .j a v a2 s . c o m*/ executor.setStreamHandler(new PumpStreamHandler(new CollectingLogOutputStream())); exitCode = executor.execute(CommandLine.parse("numactl --hardware")); } catch (IOException e) { exitCode = -1; } return (exitCode == 0); }
From source file:ro.cosu.vampires.server.resources.local.LocalResource.java
private void execute(CommandLine cmd) throws IOException { executor.setWorkingDirectory(Paths.get("").toAbsolutePath().toFile()); executor.setStreamHandler(new PumpStreamHandler(collectingLogOutputStream)); // watchdog for 3 hours. a bit excessive ? executor.setWatchdog(new ExecuteWatchdog(1000 * 60 * 60 * 3)); int exitCode = 0; try {//from ww w .j a va 2 s. c om LOG.debug("execute {}", cmd.toString()); exitCode = executor.execute(cmd); if (exitCode != 0) { LOG.error("Output {}", collectingLogOutputStream.getLines()); throw new IOException("Non zero exit code"); } } catch (IOException e) { LOG.debug("{} has failed with error {}: {}", this, exitCode, e); LOG.debug("{}", Joiner.on("\n").join(collectingLogOutputStream.getLines())); throw e; } }
From source file:util.Utility.java
/** * command line execution/* ww w . ja v a 2 s .c o m*/ * * @param line command line * @return output string of running this command line */ public static String exec(String line) { //String line = "wc -l " + "/home/hathitrust/solr/ToVM_Solr_related/test/apache-tomcat-6.0.35/bin/proxy_logs/logfile"; CommandLine command = CommandLine.parse(line); DefaultExecutor executor = new DefaultExecutor(); //int exitValue = executor.execute(command); ByteArrayOutputStream stdout = new ByteArrayOutputStream(); PumpStreamHandler pump_stream_handler = new PumpStreamHandler(stdout); executor.setStreamHandler(pump_stream_handler); int exitValue = 0; try { exitValue = executor.execute(command); } catch (ExecuteException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } // System.out.println(exitValue); // System.out.println(stdout.toString()); return stdout.toString(); }