List of usage examples for org.apache.commons.exec CommandLine addArgument
public CommandLine addArgument(final String argument)
From source file:com.netflix.genie.web.services.impl.JobKillServiceV3.java
private void killJobOnUnix(final int pid) throws GenieException { try {// w w w . j av a2 s . com // Ensure this process check can't be timed out final Instant tomorrow = Instant.now().plus(1, ChronoUnit.DAYS); final ProcessChecker processChecker = this.processCheckerFactory.get(pid, tomorrow); processChecker.checkProcess(); } catch (final ExecuteException ee) { // This means the job was done already log.debug("Process with pid {} is already done", pid); return; } catch (final IOException ioe) { throw new GenieServerException("Unable to check process status for pid " + pid, ioe); } // TODO: Do we need retries? // This means the job client process is still running try { final CommandLine killCommand; if (this.runAsUser) { killCommand = new CommandLine("sudo"); killCommand.addArgument("kill"); } else { killCommand = new CommandLine("kill"); } killCommand.addArguments(Integer.toString(pid)); this.executor.execute(killCommand); } catch (final IOException ioe) { throw new GenieServerException("Unable to kill process " + pid, ioe); } }
From source file:de.akquinet.innovation.play.maven.Play2PackageMojo.java
private void packageApplication() throws MojoExecutionException { String line = getPlay2().getAbsolutePath(); CommandLine cmdLine = CommandLine.parse(line); cmdLine.addArgument("package"); DefaultExecutor executor = new DefaultExecutor(); if (timeout > 0) { ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout); executor.setWatchdog(watchdog);//from ww w . j a v a2s. c o m } executor.setWorkingDirectory(project.getBasedir()); executor.setExitValue(0); try { executor.execute(cmdLine, getEnvironment()); } catch (IOException e) { throw new MojoExecutionException("Error during packaging", e); } }
From source file:de.akquinet.innovation.play.maven.Play2PackageMojo.java
private void packageDistribution() throws MojoExecutionException { String line = getPlay2().getAbsolutePath(); CommandLine cmdLine = CommandLine.parse(line); cmdLine.addArgument("dist"); DefaultExecutor executor = new DefaultExecutor(); if (timeout > 0) { ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout); executor.setWatchdog(watchdog);// w w w.j a v a 2 s . c o m } executor.setWorkingDirectory(project.getBasedir()); executor.setExitValue(0); try { executor.execute(cmdLine, getEnvironment()); } catch (IOException e) { throw new MojoExecutionException("Error during distribution creation", e); } }
From source file:eu.creatingfuture.propeller.blocklyprop.propeller.OpenSpin.java
protected boolean compileForRam(String executable, File sourceFile, File destinationFile) { try {/*ww w . j a v a 2s . 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("-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 . ja v a2 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.blocklyprop.propeller.OpenSpin.java
/** * https://code.google.com/p/open-source-spin-compiler/wiki/CommandLine * * @param executable//ww w . j a v a 2 s.co 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.webLoader.propeller.OpenSpin.java
/** * https://code.google.com/p/open-source-spin-compiler/wiki/CommandLine * * @param executable/*from www.java 2s .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:com.adaptris.hpcc.DfuPlusWrapper.java
private JobStatus requestStatus(String wuid) throws ProduceException, AbortJobException, PasswordException, IOException { DfuplusOutputParser stdout = new JobStatusParser(wuid); CommandLine cmdLine = createQuery(wuid); cmdLine.addArgument("action=status"); executeInternal(cmdLine, stdout);/* w w w .j ava 2 s .c o m*/ return stdout.getJobStatus(); }
From source file:com.adaptris.hpcc.DfuPlusWrapper.java
private void abortJob(String wuid) { if (isBlank(wuid)) { return;//from ww w. ja va 2 s . c o m } try { CommandLine cmdLine = createQuery(wuid); cmdLine.addArgument("action=abort"); executeInternal(cmdLine, new NoOpDfuplusOutputParser()); } catch (Exception ignored) { } }
From source file:com.walmart.gatling.commons.ScriptExecutor.java
private void runCancelJob(Master.Job message) { if (getAbortStatus(message.abortUrl, message.trackingId)) { CommandLine cmdLine = new CommandLine("/bin/bash"); cmdLine.addArgument(agentConfig.getJob().getJobArtifact("cancel")); cmdLine.addArgument(message.jobId); DefaultExecutor killExecutor = new DefaultExecutor(); ExecuteWatchdog watchdog = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT); killExecutor.setWatchdog(watchdog); try {//from ww w. java2 s .com log.info("Cancel command: {}", cmdLine); killExecutor.execute(cmdLine); } catch (IOException e) { log.error(e, "Error cancelling job"); } } }