retval = StringUtils.chomp(stdout.toString()); if (resultHandler.getException() != null) { logger.warn("{}", resultHandler.getException().getMessage()); } else { logger.debug("exit code '{}', result '{}'", exitCode, retval);
@Override public void onProcessFailed(final ExecuteException e) { super.onProcessFailed(e); if (watchdog != null && watchdog.killedProcess()) { LOG.warn("Installation killed by watchdog"); } else { LOG.warn("Installation failed due to [{}]", e.getMessage()); } } }
@Override public String handle(Task aTask) throws Exception { File scriptFile = File.createTempFile("_script", ".sh"); File logFile = File.createTempFile("log", null); FileUtils.writeStringToFile(scriptFile, aTask.getRequiredString("script")); try (PrintStream stream = new PrintStream(logFile);) { Process chmod = Runtime.getRuntime().exec(String.format("chmod u+x %s",scriptFile.getAbsolutePath())); int chmodRetCode = chmod.waitFor(); if(chmodRetCode != 0) { throw new ExecuteException("Failed to chmod", chmodRetCode); } CommandLine cmd = new CommandLine (scriptFile.getAbsolutePath()); logger.debug("{}",cmd); DefaultExecutor exec = new DefaultExecutor(); exec.setStreamHandler(new PumpStreamHandler(stream)); exec.execute(cmd); return FileUtils.readFileToString(logFile); } catch (ExecuteException e) { throw new ExecuteException(e.getMessage(),e.getExitValue(), new RuntimeException(FileUtils.readFileToString(logFile))); } finally { FileUtils.deleteQuietly(logFile); FileUtils.deleteQuietly(scriptFile); } }
@Override public Object handle(Task aTask) throws Exception { List<String> options = aTask.getList("options", String.class); CommandLine cmd = new CommandLine ("ffmpeg"); options.forEach(o->cmd.addArgument(o)); log.debug("{}",cmd); DefaultExecutor exec = new DefaultExecutor(); File tempFile = File.createTempFile("log", null); try (PrintStream stream = new PrintStream(tempFile);) { exec.setStreamHandler(new PumpStreamHandler(stream)); int exitValue = exec.execute(cmd); return exitValue!=0?FileUtils.readFileToString(tempFile):cmd.toString(); } catch (ExecuteException e) { throw new ExecuteException(e.getMessage(),e.getExitValue(), new RuntimeException(FileUtils.readFileToString(tempFile))); } finally { FileUtils.deleteQuietly(tempFile); } }
@Override public Map<String,Object> handle (Task aTask) throws Exception { CommandLine cmd = new CommandLine ("mediainfo"); cmd.addArgument(aTask.getRequiredString("input")); log.debug("{}",cmd); DefaultExecutor exec = new DefaultExecutor(); File tempFile = File.createTempFile("log", null); try (PrintStream stream = new PrintStream(tempFile);) { exec.setStreamHandler(new PumpStreamHandler(stream)); exec.execute(cmd); return parse(FileUtils.readFileToString(tempFile)); } catch (ExecuteException e) { throw new ExecuteException(e.getMessage(),e.getExitValue(), new RuntimeException(FileUtils.readFileToString(tempFile))); } finally { FileUtils.deleteQuietly(tempFile); } }
LOG.error("ExecException while executing command: " + command.toString() + " - " + ee.getMessage());
import org.apache.commons.exec.*; import java.io.IOException; public class NativeKillerRunnable implements Runnable { private static final Logger logger = LoggerFactory.getLogger(NativeKillerRunnable.class); @Override public void run() { String commandtoexec = "top -n 1 -m 100"; CommandLine cmdLine = CommandLine.parse(commandtoexec); DefaultExecutor executor = new DefaultExecutor(); try { PumpStreamHandler psh = new PumpStreamHandler(new LogOutputStream() { @Override protected void processLine(String s, int i) { s = s.trim(); //check for name of your binary process if(s.contains("mybinary")) { String[] strings = s.split(" "); android.os.Process.killProcess(Integer.parseInt(strings[0])); logger.info("killed mybinary process with pid = "+strings[0]); } } }); executor.setStreamHandler(psh); executor.execute(cmdLine); } catch (ExecuteException executeException) { logger.error("caught exception while killing mybinary process "+executeException.getMessage()); } }
return executor.execute(cli, env); // this throws ExecuteException if process return code != 0 } catch (ExecuteException e) { throw new LauncherException("Failed to run Maven: " + e.getMessage() + "\n" + cli, e);
executor.execute(commandLine); } catch (final ExecuteException e) { System.out.println(e.getMessage()); isTimeout = true; } catch (final IOException e) {
@Override public Map<String,Object> handle(Task aTask) throws Exception { CommandLine cmd = new CommandLine ("ffprobe"); cmd.addArgument("-v") .addArgument("quiet") .addArgument("-print_format") .addArgument("json") .addArgument("-show_error") .addArgument("-show_format") .addArgument("-show_streams") .addArgument(aTask.getRequiredString("input")); log.debug("{}",cmd); DefaultExecutor exec = new DefaultExecutor(); File tempFile = File.createTempFile("log", null); try (PrintStream stream = new PrintStream(tempFile);) { exec.setStreamHandler(new PumpStreamHandler(stream)); exec.execute(cmd); return parse(FileUtils.readFileToString(tempFile)); } catch (ExecuteException e) { throw new ExecuteException(e.getMessage(),e.getExitValue(), new RuntimeException(FileUtils.readFileToString(tempFile))); } finally { FileUtils.deleteQuietly(tempFile); } }
retval = StringUtils.chomp(stdout.toString()); if (resultHandler.getException() != null) { logger.warn("{}", resultHandler.getException().getMessage()); } else { logger.debug("exit code '{}', result '{}'", exitCode, retval);
retval = StringUtils.chomp(stdout.toString()); if (resultHandler.getException() != null) { logger.warn("{}", resultHandler.getException().getMessage()); } else { logger.debug("exit code '{}', result '{}'", exitCode, retval);
retval = StringUtils.chomp(stdout.toString()); if (resultHandler.getException() != null) { logger.warn("{}", resultHandler.getException().getMessage()); } else { logger.debug("exit code '{}', result '{}'", exitCode, retval);
LOG.debug("outputStream: " + outputStream.toString()); entry.put("exitValue", String.valueOf(resultHandler.getExitValue())); entry.put("outputStream", outputStream.toString() + e.getMessage()); e.printStackTrace(); return entry;
ExecuteException e = handler.getException(); if (e != null) { LOGGER.log(Level.SEVERE, handler.getException().getMessage(), handler.getException());
ExecuteException e = handler.getException(); if (e != null) { LOGGER.log(Level.SEVERE, handler.getException().getMessage(), handler.getException());