List of usage examples for org.apache.commons.exec CommandLine CommandLine
public CommandLine(final CommandLine other)
From source file:edu.buffalo.fusim.ReadSimulator.java
public void run(String artBinPath, File fusionFile, String outputPrefix, int readLength, int meanFragSize, int readCoverage, boolean pairedEnd) { // Example art call: // art_illumina -i fusion.txt -o testsim -l 75 -f 10 -p -m 400 -s 10 CommandLine cmdLine = new CommandLine(artBinPath); // the filename of input DNA reference cmdLine.addArgument("-i"); cmdLine.addArgument("${file}"); // the prefix of output files cmdLine.addArgument("-o"); cmdLine.addArgument("${outputPrefix}"); // the length of reads to be simulated cmdLine.addArgument("-l"); cmdLine.addArgument("" + readLength); // the fold of read coverage to be simulated cmdLine.addArgument("-f"); cmdLine.addArgument("" + readCoverage); if (pairedEnd) { // indicate a paired-end read simulation cmdLine.addArgument("-p"); // the mean size of DNA fragments for paired-end simulations cmdLine.addArgument("-m"); cmdLine.addArgument("" + meanFragSize); // the standard deviation of DNA fragment size for paired-end simulations. cmdLine.addArgument("-s"); cmdLine.addArgument("10"); }//from ww w . ja v a 2 s .com // quite - turn off end of run summary cmdLine.addArgument("-q"); Map map = new HashMap(); map.put("file", fusionFile); map.put("outputPrefix", outputPrefix); cmdLine.setSubstitutionMap(map); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(0); // Timeout after 5 minutes ExecuteWatchdog watchdog = new ExecuteWatchdog(300000); executor.setWatchdog(watchdog); try { int exitValue = executor.execute(cmdLine); } catch (Exception e) { logger.fatal("Failed to execute ART for simulating Illumina reads: " + e.getMessage()); } }
From source file:io.werval.maven.MavenDevShellSPI.java
public MavenDevShellSPI(URL[] applicationSources, URL[] applicationClassPath, URL[] runtimeClassPath, Set<File> sources, SourceWatcher watcher, File rootDir, String rebuildPhase) { super(applicationSources, applicationClassPath, runtimeClassPath, sources, watcher, false); pom = new File(rootDir, "pom.xml"); cmdLine = new CommandLine("mvn"); cmdLine.addArgument("-f"); cmdLine.addArgument(pom.getAbsolutePath()); cmdLine.addArgument(rebuildPhase);//from w w w .ja v a 2s . c o m }
From source file:hu.bme.mit.trainbenchmark.sql.process.MySqlProcess.java
public static void runShell(final String shellCommand) throws ExecuteException, IOException { final Executor executor = new DefaultExecutor(); final CommandLine commandLine = new CommandLine("/bin/bash"); commandLine.addArgument("-c"); commandLine.addArgument(shellCommand, false); executor.execute(commandLine);/*from ww w .ja v a 2 s . c o m*/ }
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 . jav a 2 s .com*/ FileUtils.deleteQuietly(tempFile); } }
From source file:com.muk.services.util.BarcodeServiceImpl.java
@Override public File generateBarcode(File path, String giftCardId) { CommandLine cmdLine = null;/*from w w w . j a va2 s. c om*/ if (System.getProperty("os.name").equals("Linux")) { cmdLine = new CommandLine("convert"); } else { cmdLine = new CommandLine("convert.exe"); } cmdLine.addArgument("-font"); cmdLine.addArgument("Free-3-of-9-Extended-Regular"); cmdLine.addArgument("-pointsize"); cmdLine.addArgument("40"); cmdLine.addArgument("-bordercolor"); cmdLine.addArgument("white"); cmdLine.addArgument("-border"); cmdLine.addArgument("10x10"); cmdLine.addArgument("label:${giftCardId}"); cmdLine.addArgument("${outfile}"); Map<String, Object> map = new HashMap<String, Object>(); map.put("giftCardId", giftCardId); map.put("outfile", path); cmdLine.setSubstitutionMap(map); ProcessExecutor executor = new ProcessExecutor(); try { if (0 == executor.runCommandLine(cmdLine, 100000)) { return path; } } catch (IOException ex) { LOG.error("Failed to execute imagemagick", ex); } return null; }
From source file:net.robyf.dbpatcher.util.MySqlUtil.java
/** * Drops an existing MySQL database.//from w w w . j a va 2 s . com * * @param databaseName The name of the database to be dropped * @param username Username of the MySQL administration user * @param password Password of the MySQL administration user */ public static void dropDatabase(final String databaseName, final String username, final String password) { CommandLine command = new CommandLine("mysqladmin"); addCredentials(command, username, password); command.addArgument("drop"); command.addArgument("-f"); command.addArgument(databaseName); execute(command); }
From source file:name.martingeisse.webide.nodejs.AbstractNodejsServer.java
/** * Starts this server./*from ww w . j av a 2s . c o m*/ */ public void start() { // determine the path of the associated script URL url = getScriptUrl(); if (!url.getProtocol().equals("file")) { throw new RuntimeException("unsupported protocol for associated script URL: " + url); } File scriptFile = new File(url.getPath()); // build the command line CommandLine commandLine = new CommandLine(Configuration.getBashPath()); commandLine.addArgument("--login"); commandLine.addArgument("-c"); commandLine.addArgument("node " + scriptFile.getName(), false); // build I/O streams ByteArrayInputStream inputStream = null; OutputStream outputStream = System.err; OutputStream errorStream = System.err; ExecuteStreamHandler streamHandler = new PumpStreamHandler(outputStream, errorStream, inputStream); // build an environment map that contains the path to the node_modules Map<String, String> environment = new HashMap<String, String>(); environment.put("NODE_PATH", new File("lib/node_modules").getAbsolutePath()); // run Node.js Executor executor = new DefaultExecutor(); executor.setProcessDestroyer(new ShutdownHookProcessDestroyer()); executor.setStreamHandler(streamHandler); try { executor.setWorkingDirectory(scriptFile.getParentFile()); executor.execute(commandLine, environment, new ExecuteResultHandler() { @Override public void onProcessFailed(ExecuteException e) { } @Override public void onProcessComplete(int exitValue) { } }); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:de.torstenwalter.maven.plugins.ImpdpMojo.java
public void execute() throws MojoExecutionException, MojoFailureException { CommandLine commandLine = new CommandLine(impdp); addCommonArguments(commandLine);// w w w. ja v a 2 s .co m if (StringUtils.isNotEmpty(remap_tablespace)) { commandLine.addArgument("REMAP_TABLESPACE=" + remap_tablespace); } if (StringUtils.isNotEmpty(remap_schema)) { commandLine.addArgument("REMAP_SCHEMA=" + remap_schema); } if (StringUtils.isNotEmpty(table_exists_action)) { commandLine.addArgument("TABLE_EXISTS_ACTION=" + table_exists_action); } getLog().info("Executing command line: " + obfuscateCredentials(commandLine.toString(), getCredentials())); Executor exec = new DefaultExecutor(); exec.setStreamHandler(new PumpStreamHandler(System.out, System.err)); try { exec.execute(commandLine); } catch (ExecuteException e) { throw new MojoExecutionException("Command execution failed.", e); } catch (IOException e) { throw new MojoExecutionException("Command execution failed.", e); } }
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 www. j av a2s . c om 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.tribuneqa.utilities.FrameworkUtilities.java
public void appiumStart() throws IOException, InterruptedException { // Start command prompt In background. CommandLine command = new CommandLine("cmd"); // Add different arguments In command line which requires to start appium server. command.addArgument("/c"); // Add different arguments In command line which requires to start appium server. command.addArgument("appium"); command.addArgument("-a"); command.addArgument("10.20.121.69"); command.addArgument("-p"); command.addArgument("8001"); command.addArgument("-U"); command.addArgument("4d0081724d5741c7"); // Execute command line arguments to start appium server. DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler(); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(1);//from w w w.j av a 2 s .co m executor.execute(command, resultHandler); Thread.sleep(15000); }