List of usage examples for org.apache.commons.exec CommandLine CommandLine
public CommandLine(final CommandLine other)
From source file:eu.creatingfuture.propeller.blocklyprop.propellent.Propellent.java
public boolean compile(File file) { try {/*w ww . j av a2 s .com*/ 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:com.adaptris.hpcc.SprayToThorTest.java
@Test public void testCSVFormat() throws Exception { SprayToThor sprayToThor = new SprayToThor(); sprayToThor.setSprayFormat(new CSVSprayFormat()); CommandLine cmdLine = new CommandLine("/bin/dfuplus"); sprayToThor.addFormatArguments(cmdLine); assertEquals(1, cmdLine.getArguments().length); assertEquals("format=csv", cmdLine.getArguments()[0]); }
From source file:com.adaptris.hpcc.DfuplusConnection.java
public CommandLine createCommand() throws PasswordException, IOException { File dfuPlus = validateCmd(getDfuplusCommand()); CommandLine cmdLine = new CommandLine(dfuPlus.getCanonicalPath()); return addArguments(cmdLine); }
From source file:name.martingeisse.webide.features.verilog.compiler.VerilogBuilder.java
private void compile(long workspaceId, final JsonAnalyzer descriptorAnalyzer, ResourcePath inputFilePath, ResourcePath outputFilePath) {/*from w w w . j a va 2 s. c o m*/ try { // prepare ResourceHandle inputFile = new ResourceHandle(workspaceId, inputFilePath); ResourceHandle outputFile = new ResourceHandle(workspaceId, outputFilePath); // read the input file byte[] inputData = inputFile.readBinaryFile(false); if (inputData == null) { return; } // delete previous output file outputFile.delete(); // build the command line CommandLine commandLine = new CommandLine(Configuration.getIverilogPath()); commandLine.addArgument("-o"); commandLine.addArgument(Configuration.getStdoutPath()); commandLine.addArgument(Configuration.getStdinPath()); // build I/O streams ByteArrayInputStream inputStream = new ByteArrayInputStream(inputData); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); OutputStream errorStream = System.err; ExecuteStreamHandler streamHandler = new PumpStreamHandler(outputStream, errorStream, inputStream); // run Icarus Executor executor = new DefaultExecutor(); executor.setStreamHandler(streamHandler); executor.execute(commandLine); // create the output file outputFile.writeFile(outputStream.toByteArray(), true, true); } catch (IOException e) { // TODO error message logger.error(e); return; } }
From source file:com.sonar.it.jenkins.orchestrator.container.JenkinsWrapper.java
public void start() { if (started.getAndSet(true)) { throw new IllegalStateException("App server is already started"); }// w w w .j a v a 2s . c o m LOG.info("Start jenkins on port " + port + " in " + workingDir); resultHandler = createResultHandler(); try { FileUtils.forceMkdir(workingDir); CommandLine command; if (javaHome == null) { command = new CommandLine("java"); } else { command = new CommandLine(FileUtils.getFile(javaHome, "bin", "java")); } command.addArgument("-Xmx512M"); command.addArgument("-XX:MaxPermSize=128m"); command.addArgument("-Djava.awt.headless=true"); command.addArgument("-Djenkins.install.runSetupWizard=false"); command.addArgument("-DJENKINS_HOME=" + workingDir.getAbsolutePath()); String jaCoCoArgument = JaCoCoArgumentsBuilder.getJaCoCoArgument(config); if (jaCoCoArgument != null) { LOG.info("JaCoCo enabled"); command.addArgument(jaCoCoArgument); } command.addArgument("-jar"); command.addArgument("jenkins-war-" + server.getVersion() + ".war"); command.addArgument("--httpPort=" + port); command.addArgument("--ajp13Port=-1"); executor.setWorkingDirectory(workingDir.getParentFile()); executor.execute(command, resultHandler); } catch (IOException e) { throw new IllegalStateException("Can't start jenkins", e); } waitForJenkinsToStart(); }
From source file:com.netflix.genie.web.services.impl.JobKillServiceV3Test.java
/** * Setup for the tests./* ww w . java 2s. c om*/ * * @throws IOException if the job directory cannot be created */ @Before public void setup() throws IOException { Assume.assumeTrue(SystemUtils.IS_OS_UNIX); final File tempDirectory = Files.createTempDir(); this.genieWorkingDir = new FileSystemResource(tempDirectory); Files.createParentDirs(new File(tempDirectory.getPath() + "/" + ID + "/genie/x")); this.jobSearchService = Mockito.mock(JobSearchService.class); this.executor = Mockito.mock(Executor.class); this.genieEventBus = Mockito.mock(GenieEventBus.class); this.processCheckerFactory = Mockito.mock(ProcessChecker.Factory.class); this.processChecker = Mockito.mock(ProcessChecker.class); this.service = new JobKillServiceV3(HOSTNAME, this.jobSearchService, this.executor, false, this.genieEventBus, this.genieWorkingDir, GenieObjectMapper.getMapper(), processCheckerFactory); this.killCommand = new CommandLine("kill"); this.killCommand.addArguments(Integer.toString(PID)); }
From source file:com.base.exec.TutorialTest.java
/** * Simulate printing a PDF document./* w w w . j a v a 2s . co m*/ * * @param file * the file to print * @param printJobTimeout * the printJobTimeout (ms) before the watchdog terminates the * print process * @param printInBackground * printing done in the background or blocking * @return a print result handler (implementing a future) * @throws IOException * the test failed */ public PrintResultHandler print(final File file, final long printJobTimeout, final boolean printInBackground) throws IOException { int exitValue; ExecuteWatchdog watchdog = null; PrintResultHandler resultHandler; // build up the command line to using a 'java.io.File' final Map<String, File> map = new HashMap<String, File>(); map.put("file", file); final CommandLine commandLine = new CommandLine(acroRd32Script); // commandLine.addArgument("/p"); // commandLine.addArgument("/h"); // commandLine.addArgument("${file}"); // commandLine.setSubstitutionMap(map); // // create the executor and consider the exitValue '1' as success final Executor executor = new DefaultExecutor(); executor.setExitValue(0); // create a watchdog if requested if (printJobTimeout > 0) { watchdog = new ExecuteWatchdog(printJobTimeout); executor.setWatchdog(watchdog); } // pass a "ExecuteResultHandler" when doing background printing if (printInBackground) { System.out.println("[print] Executing non-blocking print job ..."); resultHandler = new PrintResultHandler(watchdog); executor.execute(commandLine, resultHandler); } else { System.out.println("[print] Executing blocking print job ..."); exitValue = executor.execute(commandLine); resultHandler = new PrintResultHandler(exitValue); } return resultHandler; }
From source file:com.vmware.bdd.usermgmt.job.CfgUserMgmtOnMgmtVMExecutor.java
private void execChefClient(String specFilePath) { CommandLine cmdLine = new CommandLine(sudoCmd).addArgument("chef-client").addArgument("-z") .addArgument("-j").addArgument("\"" + specFilePath + "\"").addArgument("-c") .addArgument("/opt/serengeti/.chef/knife.rb"); execCommand(cmdLine);//from w w w . ja v a2 s . c o m }
From source file:com.github.genium_framework.appium.support.command.CommandManager.java
/** * Constructs a CommandLine object depending on the current running * operating system using the number of arguments passed to it. * * @param command The native OS command to run or an absolute path to an * executable to run./*from w ww. ja va 2 s.co m*/ * @param parameters The command parameters. * @param arguments String arguments of the command to formulate from. * @return CommandLine object that represents the command you want to * execute. */ public static CommandLine createCommandLine(String command, String[] parameters, String... arguments) { CommandLine commanddLine = null; // add the command to be executed if (OS.isFamilyWindows()) { commanddLine = new CommandLine("\"" + command + "\""); } else if (OS.isFamilyMac() || OS.isFamilyUnix()) { commanddLine = new CommandLine(command.contains(" ") ? "'" + command + "'" : command); } else { throw new UnsupportedOperationException("Unsupported operating system."); } // add the command parameters if (OS.isFamilyWindows()) { for (String parameter : parameters) { commanddLine.addArgument("\"" + parameter + "\"", false); } } else if (OS.isFamilyMac() || OS.isFamilyUnix()) { for (String parameter : parameters) { commanddLine.addArgument(parameter.contains(" ") ? "'" + parameter + "'" : parameter, false); } } // add the command arguments for (String argument : arguments) { // you have to pass the false value and disable handling quoting // otherwise the OS won't be able to run the shell file on MAc OS commanddLine.addArgument(argument, false); } return commanddLine; }
From source file:com.tascape.qa.th.android.comm.Adb.java
private static void loadAllSerials() { SERIALS.clear();/*from w w w . ja va 2 s . com*/ String serials = SystemConfiguration.getInstance().getProperty(SYSPROP_SERIALS); if (null != serials) { LOG.info("Use specified devices from system property {}={}", SYSPROP_SERIALS, serials); SERIALS.addAll(Lists.newArrayList(serials.split(","))); } else { CommandLine cmdLine = new CommandLine(ADB); cmdLine.addArgument("devices"); LOG.debug("{}", cmdLine.toString()); List<String> output = new ArrayList<>(); Executor executor = new DefaultExecutor(); executor.setStreamHandler(new ESH(output)); try { if (executor.execute(cmdLine) != 0) { throw new RuntimeException(cmdLine + " failed"); } } catch (IOException ex) { throw new RuntimeException(cmdLine + " failed", ex); } output.stream().filter((line) -> (line.endsWith("device"))).forEach((line) -> { String s = line.split("\\t")[0]; LOG.info("serial {}", s); SERIALS.add(s); }); } if (SERIALS.isEmpty()) { throw new RuntimeException("No device detected."); } }