List of usage examples for org.apache.commons.exec DefaultExecutor execute
public int execute(final CommandLine command) throws ExecuteException, IOException
From source file:eu.creatingfuture.propeller.blocklyprop.propellent.Propellent.java
public boolean compile(File file) { try {/* w ww . ja v a 2 s . co m*/ Map map = new HashMap(); map.put("file", file); CommandLine cmdLine = new CommandLine("propellent/Propellent.exe"); cmdLine.addArgument("/compile"); cmdLine.addArgument("/gui").addArgument("OFF"); cmdLine.addArgument("${file}"); cmdLine.setSubstitutionMap(map); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValues(new int[] { 402, 101 }); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream); executor.setStreamHandler(streamHandler); try { exitValue = executor.execute(cmdLine); } catch (ExecuteException ee) { exitValue = ee.getExitValue(); logger.log(Level.SEVERE, "Unexpected exit value: {0}", exitValue); return false; } output = outputStream.toString(); // 101 = Compile error // 402 = Compile succesfull if (exitValue == 101) { return false; } // System.out.println("output: " + output); /* Scanner scanner = new Scanner(output); Pattern chipFoundPattern = Pattern.compile(".*?(EVT:505).*?"); Pattern pattern = Pattern.compile(".*?found on (?<comport>[a-zA-Z0-9]*).$"); while (scanner.hasNextLine()) { String portLine = scanner.nextLine(); if (chipFoundPattern.matcher(portLine).matches()) { Matcher portMatch = pattern.matcher(portLine); if (portMatch.find()) { // String port = portMatch.group("comport"); } } } */ // System.out.println("output: " + output); // System.out.println("exitValue: " + exitValue); return true; } catch (IOException ioe) { logger.log(Level.SEVERE, null, ioe); return false; } }
From source file:net.ladenthin.snowman.imager.run.streamer.Streamer.java
@Override public void run() { final CImager conf = ConfigurationSingleton.ConfigurationSingleton.getImager(); for (;;) {// ww w .ja v a 2 s . com if (WatchdogSingleton.WatchdogSingleton.getWatchdog().getKillFlag() == true) { LOGGER.trace("killFlag == true"); return; } final CommandLine cmdLine = new CommandLine(streamer); // final CommandLine cmdLine = new CommandLine("sleep"); // cmdLine.addArgument("200"); cmdLine.addArgument("-c"); cmdLine.addArgument(conf.getStreamer().getDevice()); cmdLine.addArgument("-t"); cmdLine.addArgument( String.valueOf(conf.getStreamer().getFramesPerSecond() * conf.getStreamer().getRecordTime())); cmdLine.addArgument("-r"); cmdLine.addArgument(String.valueOf(conf.getStreamer().getFramesPerSecond())); cmdLine.addArgument("-s"); cmdLine.addArgument(conf.getStreamer().getResolutionX() + "x" + conf.getStreamer().getResolutionY()); cmdLine.addArgument("-o"); cmdLine.addArgument(conf.getStreamer().getPath() + File.separator + conf.getSnowmanServer().getCameraname() + "_" + (long) (System.currentTimeMillis() / 1000) + "_" + conf.getStreamer().getFramesPerSecond() + "_00000000.jpeg"); LOGGER.trace("cmdLine: {}", cmdLine); // 10 seconds should be more than enough final long safetyTimeWindow = 10000; final DefaultExecutor executor = new DefaultExecutor(); final long timeout = 1000 * (conf.getStreamer().getRecordTime() + safetyTimeWindow); // final long timeout = 5000; LOGGER.trace("timeout: {}", timeout); final ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout); executor.setWatchdog(watchdog); try { LOGGER.debug("start process"); final int exitValue = executor.execute(cmdLine); LOGGER.debug("process executed"); LOGGER.trace("exitValue: {}", exitValue); } catch (IOException e) { if (watchdog.killedProcess()) { LOGGER.warn("Process was killed on purpose by the watchdog "); } else { LOGGER.error("Process exited with an error."); Imager.waitALittleBit(5000); } } LOGGER.trace("loop end"); } }
From source file:io.vertx.config.vault.utils.VaultProcess.java
public void runAndProcess(String command, Consumer<String> processor) { String cli = executable.getAbsolutePath() + " " + command; System.out.println(">> " + cli); CommandLine parse = CommandLine.parse(cli); DefaultExecutor executor = new DefaultExecutor(); PumpStreamHandler pump = new PumpStreamHandler(new VaultOutputStream().addExtractor(processor), System.err); ExecuteWatchdog watchDog = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT); executor.setWatchdog(watchDog);// w w w .j av a 2 s . com executor.setStreamHandler(pump); try { executor.execute(parse); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.github.cshubhamrao.MediaConverter.MainUI.java
/** Runs ffmpeg -version */ @Override/*from ww w.j av a 2 s . c o m*/ protected Void doInBackground() { ffmpeg = FFMpegLoader.getFFMpegExecutable(); if (ffmpeg != null) { try { cmd = new CommandLine(ffmpeg); cmd.addArgument("-version"); OutputStream outputStream = new ByteArrayOutputStream(); DefaultExecutor exec = new DefaultExecutor(); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream); exec.setStreamHandler(streamHandler); ExecuteWatchdog watchdog = new ExecuteWatchdog(10000); exec.setWatchdog(watchdog); exec.execute(cmd); publish(outputStream.toString()); } catch (ExecuteException ex) { Logger.getLogger(DisplayVersion.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(DisplayVersion.class.getName()).log(Level.SEVERE, null, ex); } } else { try { Thread.sleep(1000); } catch (InterruptedException ex) { Logger.getLogger(DisplayVersion.class.getName()).log(Level.SEVERE, null, ex); } } return null; }
From source file:be.tarsos.transcoder.ffmpeg.FFMPEGExecutor.java
/** * Executes the ffmpeg process with the previous given arguments. * /*from ww w.j a v a 2 s . c om*/ * @return The standard output of the child process. * * @throws IOException * If the process call fails. */ public String execute() throws IOException { CommandLine cmdLine = new CommandLine(ffmpegExecutablePath); int fileNumber = 0; Map<String, File> map = new HashMap<String, File>(); for (int i = 0; i < args.size(); i++) { final String arg = args.get(i); final Boolean isFile = argIsFile.get(i); if (isFile) { String key = "file" + fileNumber; map.put(key, new File(arg)); cmdLine.addArgument("'${" + key + "}'", false); fileNumber++; } else { cmdLine.addArgument(arg); } } cmdLine.setSubstitutionMap(map); LOG.fine("Execute: " + cmdLine); DefaultExecutor executor = new DefaultExecutor(); //5minutes wait ExecuteWatchdog watchdog = new ExecuteWatchdog(60 * 1000 * 5); executor.setWatchdog(watchdog); ByteArrayOutputStream out = new ByteArrayOutputStream(); executor.setStreamHandler(new PumpStreamHandler(out)); int[] exitValues = { 0, 1 }; executor.setExitValues(exitValues); executor.execute(cmdLine); return out.toString(); }
From source file:eu.creatingfuture.propeller.blocklyprop.propeller.OpenSpin.java
/** * https://code.google.com/p/open-source-spin-compiler/wiki/CommandLine * * @param executable//www .ja v a 2 s . c o m * @param sourceFile * @return */ protected boolean compile(String executable, File sourceFile) { try { File temporaryDestinationFile = File.createTempFile("blocklyapp", ".binary"); File libDirectory = new File(new File(System.getProperty("user.dir")), "/propeller-lib"); Map map = new HashMap(); map.put("sourceFile", sourceFile); map.put("destinationFile", temporaryDestinationFile); map.put("libDirectory", libDirectory); CommandLine cmdLine = new CommandLine(executable); cmdLine.addArgument("-o").addArgument("${destinationFile}"); cmdLine.addArgument("-L").addArgument("${libDirectory}"); cmdLine.addArgument("${sourceFile}"); cmdLine.setSubstitutionMap(map); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValues(new int[] { 0, 1 }); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream); executor.setStreamHandler(streamHandler); try { exitValue = executor.execute(cmdLine); } catch (ExecuteException ee) { exitValue = ee.getExitValue(); logger.log(Level.SEVERE, "Unexpected exit value: {0}", exitValue); success = false; return false; } finally { temporaryDestinationFile.delete(); output = outputStream.toString(); } // System.out.println("output: " + output); /* Scanner scanner = new Scanner(output); Pattern chipFoundPattern = Pattern.compile(".*?(EVT:505).*?"); Pattern pattern = Pattern.compile(".*?found on (?<comport>[a-zA-Z0-9]*).$"); while (scanner.hasNextLine()) { String portLine = scanner.nextLine(); if (chipFoundPattern.matcher(portLine).matches()) { Matcher portMatch = pattern.matcher(portLine); if (portMatch.find()) { // String port = portMatch.group("comport"); } } } */ // System.out.println("output: " + output); // System.out.println("exitValue: " + exitValue); success = true; return true; } catch (IOException ioe) { logger.log(Level.SEVERE, null, ioe); success = false; return false; } }
From source file:eu.creatingfuture.propeller.blocklyprop.propeller.OpenSpin.java
protected boolean compileForRam(String executable, File sourceFile, File destinationFile) { try {//from www . j a v a 2 s .c o m File libDirectory = new File(new File(System.getProperty("user.dir")), "/propeller-lib"); Map map = new HashMap(); map.put("sourceFile", sourceFile); map.put("destinationFile", destinationFile); map.put("libDirectory", libDirectory); CommandLine cmdLine = new CommandLine(executable); cmdLine.addArgument("-b"); cmdLine.addArgument("-o").addArgument("${destinationFile}"); cmdLine.addArgument("-L").addArgument("${libDirectory}"); cmdLine.addArgument("${sourceFile}"); cmdLine.setSubstitutionMap(map); DefaultExecutor executor = new DefaultExecutor(); // executor.setExitValues(new int[]{402, 101}); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream); executor.setStreamHandler(streamHandler); try { exitValue = executor.execute(cmdLine); } catch (ExecuteException ee) { exitValue = ee.getExitValue(); logger.log(Level.SEVERE, "Unexpected exit value: {0}", exitValue); success = false; return false; } finally { output = outputStream.toString(); } // System.out.println("output: " + output); /* Scanner scanner = new Scanner(output); Pattern chipFoundPattern = Pattern.compile(".*?(EVT:505).*?"); Pattern pattern = Pattern.compile(".*?found on (?<comport>[a-zA-Z0-9]*).$"); while (scanner.hasNextLine()) { String portLine = scanner.nextLine(); if (chipFoundPattern.matcher(portLine).matches()) { Matcher portMatch = pattern.matcher(portLine); if (portMatch.find()) { // String port = portMatch.group("comport"); } } } */ // System.out.println("output: " + output); // System.out.println("exitValue: " + exitValue); success = true; return true; } catch (IOException ioe) { logger.log(Level.SEVERE, null, ioe); success = false; return false; } }
From source file:eu.creatingfuture.propeller.blocklyprop.propeller.OpenSpin.java
protected boolean compileForEeprom(String executable, File sourceFile, File destinationFile) { try {/*from w w w .j av a 2 s . co m*/ File libDirectory = new File(new File(System.getProperty("user.dir")), "/propeller-lib"); Map map = new HashMap(); map.put("sourceFile", sourceFile); map.put("destinationFile", destinationFile); map.put("libDirectory", libDirectory); CommandLine cmdLine = new CommandLine(executable); cmdLine.addArgument("-e"); cmdLine.addArgument("-o").addArgument("${destinationFile}"); cmdLine.addArgument("-L").addArgument("${libDirectory}"); cmdLine.addArgument("${sourceFile}"); cmdLine.setSubstitutionMap(map); DefaultExecutor executor = new DefaultExecutor(); // executor.setExitValues(new int[]{402, 101}); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream); executor.setStreamHandler(streamHandler); try { exitValue = executor.execute(cmdLine); } catch (ExecuteException ee) { exitValue = ee.getExitValue(); logger.log(Level.SEVERE, "Unexpected exit value: {0}", exitValue); success = false; return false; } finally { output = outputStream.toString(); } // System.out.println("output: " + output); /* Scanner scanner = new Scanner(output); Pattern chipFoundPattern = Pattern.compile(".*?(EVT:505).*?"); Pattern pattern = Pattern.compile(".*?found on (?<comport>[a-zA-Z0-9]*).$"); while (scanner.hasNextLine()) { String portLine = scanner.nextLine(); if (chipFoundPattern.matcher(portLine).matches()) { Matcher portMatch = pattern.matcher(portLine); if (portMatch.find()) { // String port = portMatch.group("comport"); } } } */ // System.out.println("output: " + output); // System.out.println("exitValue: " + exitValue); success = true; return true; } catch (IOException ioe) { logger.log(Level.SEVERE, null, ioe); success = false; return false; } }
From source file:eu.creatingfuture.propeller.webLoader.propeller.OpenSpin.java
/** * https://code.google.com/p/open-source-spin-compiler/wiki/CommandLine * * @param executable//from w ww. j av a 2 s . c o m * @param sourceFile * @return */ protected boolean compile(String executable, File sourceFile) { try { File temporaryDestinationFile = File.createTempFile("blocklyapp", ".binary"); File libDirectory = new File(new File(System.getProperty("user.dir")), "/propeller-lib"); Map map = new HashMap(); map.put("sourceFile", sourceFile); map.put("destinationFile", temporaryDestinationFile); map.put("libDirectory", libDirectory); CommandLine cmdLine = new CommandLine(executable); cmdLine.addArgument("-o").addArgument("${destinationFile}"); cmdLine.addArgument("-L").addArgument("${libDirectory}"); cmdLine.addArgument("${sourceFile}"); cmdLine.setSubstitutionMap(map); DefaultExecutor executor = new DefaultExecutor(); // executor.setExitValues(new int[]{402, 101}); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream); executor.setStreamHandler(streamHandler); try { exitValue = executor.execute(cmdLine); } catch (ExecuteException ee) { exitValue = ee.getExitValue(); logger.log(Level.SEVERE, "Unexpected exit value: {0}", exitValue); success = false; return false; } finally { temporaryDestinationFile.delete(); output = outputStream.toString(); } // System.out.println("output: " + output); /* Scanner scanner = new Scanner(output); Pattern chipFoundPattern = Pattern.compile(".*?(EVT:505).*?"); Pattern pattern = Pattern.compile(".*?found on (?<comport>[a-zA-Z0-9]*).$"); while (scanner.hasNextLine()) { String portLine = scanner.nextLine(); if (chipFoundPattern.matcher(portLine).matches()) { Matcher portMatch = pattern.matcher(portLine); if (portMatch.find()) { // String port = portMatch.group("comport"); } } } */ // System.out.println("output: " + output); // System.out.println("exitValue: " + exitValue); success = true; return true; } catch (IOException ioe) { logger.log(Level.SEVERE, null, ioe); success = false; return false; } }
From source file:de.fischer.thotti.core.runner.NDRunner.java
private NDTestResult forkNDTestRunnerInSlaveMode(NonDistributedTestType test, TestInstanceType instance) throws IOException { NDTestResult result = new NDTestResult(); GregorianCalendar startTime;//from www. j ava 2s . com long startTimeMS; long endTimeMS; int exitCode = -9999; result.setTestId(test.getId()); result.setJVMArgs(instance.getJvmArguments()); result.setJVMArgsID(instance.getJvmArgsID()); result.setParamGrpID(instance.getName()); CommandLine cmdLine = new CommandLine("java"); if (false == StringUtils.isEmpty(instance.getJvmArguments())) { cmdLine.addArguments(instance.getJvmArguments()); } cmdLine.addArgument("-cp").addArgument(System.getProperty("java.class.path")) .addArgument(NDRunner.class.getName()).addArgument("--slave").addArgument("--executionid") .addArgument(instance.getExecutionID().toString()); System.gc(); DefaultExecutor executor = new DefaultExecutor(); startTime = (GregorianCalendar) Calendar.getInstance(); startTimeMS = startTime.getTimeInMillis(); try { exitCode = executor.execute(cmdLine); result.setSuccessfulTermination(true); result.setExitCode(exitCode); } catch (ExecuteException e) { result.setSuccessfulTermination(false); result.setExitCode(e.getExitValue()); } finally { endTimeMS = System.currentTimeMillis(); } result.setExecutionTime(endTimeMS - startTimeMS); result.setStartTime(startTime); System.out.println(result); return result; }