List of usage examples for org.apache.commons.exec CommandLine toStrings
public String[] toStrings()
From source file:org.silverpeas.core.io.media.video.ffmpeg.FFmpegUtilTest.java
@Test public void testBuildFFmpegThumbnailExtractorCommandLine() { System.setProperty(OS_KEY, "Linux"); File inputFile = new File("/silverpeas/video/", "movie.mp4"); File outputFile = new File("/silverpeas/viewer/", "thumb.jpg"); CommandLine result = FFmpegUtil.buildFFmpegThumbnailExtractorCommandLine(inputFile, outputFile, 30d); assertThat(result, is(Matchers.notNullValue())); assertThat(String.join(" ", result.toStrings()), is("ffmpeg -ss 30.0 -i " + inputFile.getAbsolutePath() + " -vframes 1 -vf scale=600:-1 " + outputFile.getAbsolutePath())); }
From source file:org.silverpeas.core.util.exec.ExternalExecution.java
/** * Execute the given external command into the context defined by the given {@link * ExternalExecution.Config}.// ww w . java2 s . c om * @param commandLine the external command to execute. * @param config the configuration that permits to perform the execution of the command with * some flexibility. * @return a {@link List} of console lines written by the external command. */ public static List<String> exec(final CommandLine commandLine, final Config config) throws ExternalExecutionException { final List<String> result = new LinkedList<>(); final List<String> errors = new LinkedList<>(); CollectingLogOutputStream logErrors = new CollectingLogOutputStream(errors); final Process process; Thread errEater = null, outEater = null; try { process = Runtime.getRuntime().exec(commandLine.toStrings()); errEater = new Thread(() -> { try { errors.addAll(IOUtils.readLines(process.getErrorStream())); } catch (final IOException e) { throw new ExternalExecutionException(e); } }); errEater.start(); outEater = new Thread(() -> { try { result.addAll(IOUtils.readLines(process.getInputStream())); } catch (final IOException e) { throw new ExternalExecutionException(e); } }); outEater.start(); process.waitFor(); int exitStatus = process.exitValue(); if (exitStatus != config.getSuccessfulExitStatusValue()) { try { errEater.join(); } catch (InterruptedException e) { } throw new RuntimeException("Exit error status : " + exitStatus + " " + logErrors.getMessage()); } } catch (final IOException | InterruptedException | RuntimeException e) { performExternalExecutionException(config, e); } finally { IOUtils.closeQuietly(logErrors); } try { outEater.join(); } catch (InterruptedException e) { } return result; }
From source file:org.silverpeas.core.viewer.util.SwfUtilTest.java
/** * Test of buildPdfToSwfCommandLine method, of class SwfUtil. *//* w w w . j a v a 2 s. c o m*/ @Test public void testLinuxBuildPdfToSwfCommandLineWithoutEndingCommand() { System.setProperty(OS_KEY, "Linux"); String endingCommand = ""; File inputFile = new File("/silverpeas/viewer/", "file ' - '' .pdf"); File outputFile = new File("/silverpeas/viewer/", "file ' - '' .swf"); CommandLine result = SwfUtil.buildPdfToSwfCommandLine(endingCommand, inputFile, outputFile); assertThat(result, is(notNullValue())); assertThat(separatorsToUnix(String.join(" ", result.toStrings())), is("pdf2swf " + "/silverpeas/viewer/file ' - '' .pdf " + "-o /silverpeas/viewer/file ' - '' .swf -f -T 9 -t -s storeallcharacters")); }
From source file:org.silverpeas.core.viewer.util.SwfUtilTest.java
/** * Test of buildPdfToSwfCommandLine method, of class SwfUtil. *//*from w ww. j av a 2 s . c om*/ @Test public void testBuildPdfToSwfCommandLineWithoutEndingCommand() { System.setProperty(OS_KEY, "Windows XP"); String endingCommand = ""; File inputFile = new File("/silverpeas/viewer/", "file ' - '' .pdf"); File outputFile = new File("/silverpeas/viewer/", "file ' - '' .swf"); CommandLine result = SwfUtil.buildPdfToSwfCommandLine(endingCommand, inputFile, outputFile); assertThat(result, is(notNullValue())); assertThat(separatorsToUnix(String.join(" ", result.toStrings())), is("pdf2swf /silverpeas/viewer/file ' - '' .pdf" + " -o /silverpeas/viewer/file ' - '' .swf -f -T 9 -t -s storeallcharacters")); }
From source file:org.wisdom.maven.utils.WisdomExecutor.java
/** * Launches the Wisdom server in background using the {@literal chameleon.sh} scripts. * This method works only on Linux and Mac OS X. * * @param mojo the mojo//from www .j av a 2 s.com * @throws MojoExecutionException if the Wisdom instance cannot be started. */ public void executeInBackground(AbstractWisdomMojo mojo) throws MojoExecutionException { File script = new File(mojo.getWisdomRootDirectory(), "chameleon.sh"); if (!script.isFile()) { throw new MojoExecutionException("The 'chameleon.sh' file does not exist in " + mojo.getWisdomRootDirectory().getAbsolutePath() + " - cannot launch Wisdom"); } // Remove the RUNNING_PID file if exists. File pid = new File(mojo.getWisdomRootDirectory(), "RUNNING_PID"); if (pid.isFile()) { mojo.getLog().info("The RUNNING_PID file is present, deleting it"); FileUtils.deleteQuietly(pid); } // We create a command line, as we are using th toString method on it. CommandLine cmdLine = new CommandLine(script); appendSystemPropertiesToCommandLine(mojo, cmdLine); try { mojo.getLog().info("Launching Wisdom Server using '" + cmdLine.toString() + "'."); // As we know which command line we are executing, we can safely execute the command. Runtime.getRuntime().exec(cmdLine.toStrings(), null, mojo.getWisdomRootDirectory()); //NOSONAR see comment } catch (IOException e) { throw new MojoExecutionException("Cannot execute Wisdom", e); } }
From source file:org.wisdom.maven.utils.WisdomExecutor.java
/** * Stops a running instance of wisdom using 'chameleon stop'. * * @param mojo the mojo/*from w w w . j a va 2 s.c o m*/ * @throws MojoExecutionException if the instance cannot be stopped */ public void stop(AbstractWisdomMojo mojo) throws MojoExecutionException { File script = new File(mojo.getWisdomRootDirectory(), "chameleon.sh"); if (!script.isFile()) { throw new MojoExecutionException("The 'chameleon.sh' file does not exist in " + mojo.getWisdomRootDirectory().getAbsolutePath() + " - cannot stop the Wisdom instance"); } // If there is a RUNNING_PID file, exit immediately. File pid = new File(mojo.getWisdomRootDirectory(), "RUNNING_PID"); if (!pid.isFile()) { mojo.getLog().info("The RUNNING_PID file does not exist, are you sure Wisdom is running ?"); return; } CommandLine cmdLine = new CommandLine(script); cmdLine.addArgument("stop"); try { mojo.getLog().info("Stopping Wisdom Server using '" + cmdLine.toString() + "'."); // As we know which command line we are executing, we can safely execute the command. Runtime.getRuntime().exec(cmdLine.toStrings(), null, mojo.getWisdomRootDirectory()); //NOSONAR } catch (IOException e) { throw new MojoExecutionException("Cannot stop Wisdom", e); } }