List of usage examples for org.apache.commons.exec ExecuteException ExecuteException
public ExecuteException(final String message, final int exitValue, final Throwable cause)
From source file:com.creactiviti.piper.plugin.ffmpeg.Mediainfo.java
@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);// w w w. j ava 2s. c o m return parse(FileUtils.readFileToString(tempFile)); } catch (ExecuteException e) { throw new ExecuteException(e.getMessage(), e.getExitValue(), new RuntimeException(FileUtils.readFileToString(tempFile))); } finally { FileUtils.deleteQuietly(tempFile); } }
From source file:com.technofovea.packbsp.packaging.ExternalController.java
protected int exec(CommandLine cl, OutputStream out) throws ExecuteException { PumpStreamHandler handler = new PumpStreamHandler(out); // Auto started/stopped executor.setStreamHandler(handler);/*from www. java 2 s.c om*/ try { logger.debug("Executing: " + cl.toString()); int exitval = executor.execute(cl, environment); logger.debug("Exit val: " + exitval); return exitval; } catch (IOException ex) { throw new ExecuteException("IO error with output", -1, ex); } }
From source file:com.creactiviti.piper.plugin.ffmpeg.Ffmpeg.java
@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 {//from ww w . j a va2 s .c o m FileUtils.deleteQuietly(tempFile); } }
From source file:com.creactiviti.piper.plugin.ffmpeg.Ffprobe.java
@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);/*from w w w . ja va 2 s. c o m*/ return parse(FileUtils.readFileToString(tempFile)); } catch (ExecuteException e) { throw new ExecuteException(e.getMessage(), e.getExitValue(), new RuntimeException(FileUtils.readFileToString(tempFile))); } finally { FileUtils.deleteQuietly(tempFile); } }
From source file:org.ng200.openolympus.cerberus.executors.OpenOlympusWatchdogExecutor.java
private static String callNativeId(boolean group) throws IOException { OpenOlympusWatchdogExecutor.ensureUserAndGroupExists(); final CommandLine commandLine = new CommandLine("id"); commandLine.addArgument(group ? "-g" : "-u"); commandLine.addArgument("olympuswatchdogchild"); final DefaultExecutor executor = new DefaultExecutor(); final ByteArrayOutputStream out = new ByteArrayOutputStream(); executor.setStreamHandler(new PumpStreamHandler(out)); executor.setWatchdog(new ExecuteWatchdog(1000)); try {/* w ww .j a v a 2s .c o m*/ executor.execute(commandLine); return out.toString(StandardCharsets.UTF_8.name()); } catch (final ExecuteException e) { throw new ExecuteException( "Couldn't find user/group id of the olympuswatchdogchild user/group: does it even exist?", e.getExitValue(), e); } }
From source file:org.ng200.openolympus.cerberus.executors.OpenOlympusWatchdogExecutor.java
private static void ensureUserAndGroupExists() throws IOException { if (alreadyEnsuredUserExists) return;/*from w w w . j a va 2 s. c o m*/ final CommandLine commandLine = new CommandLine("sudo"); commandLine.addArgument("useradd"); commandLine.addArgument("-U"); commandLine.addArgument("-M"); // Don't create home directory commandLine.addArgument("-s"); commandLine.addArgument("/bin/false"); commandLine.addArgument("olympuswatchdogchild"); final DefaultExecutor executor = new DefaultExecutor(); executor.setExitValues(new int[] { 0, /* Added user */ 9 /* User already exists */ }); executor.setWatchdog(new ExecuteWatchdog(1000)); try { executor.execute(commandLine); alreadyEnsuredUserExists = true; } catch (final ExecuteException e) { throw new ExecuteException( "Couldn't find user/group id of the olympuswatchdogchild user/group: does it even exist?", e.getExitValue(), e); } }