List of usage examples for org.apache.commons.exec CommandLine parse
public static CommandLine parse(final String line)
From source file:com.dangdang.ddframe.job.api.type.script.executor.ScriptJobExecutor.java
@Override protected void process(final ShardingContext shardingContext) { String scriptCommandLine = ((ScriptJobConfiguration) getJobRootConfig().getTypeConfig()) .getScriptCommandLine();/* w w w. j a v a 2s.c o m*/ if (Strings.isNullOrEmpty(scriptCommandLine)) { getJobExceptionHandler().handleException(getJobName(), new JobConfigurationException( "Cannot find script command line for job '{}', job is not executed.", shardingContext.getJobName())); return; } CommandLine commandLine = CommandLine.parse(scriptCommandLine); commandLine.addArgument(GsonFactory.getGson().toJson(shardingContext), false); try { executor.execute(commandLine); } catch (final IOException ex) { getJobExceptionHandler().handleException(getJobName(), ex); } }
From source file:hoot.services.command.CommandRunnerImpl.java
@Override public CommandResult exec(String command) throws IOException { logger.debug("Executing the following command: {}", command); try (OutputStream stdout = new ByteArrayOutputStream(); OutputStream stderr = new ByteArrayOutputStream()) { CommandLine cmdLine = CommandLine.parse(command); ExecuteStreamHandler executeStreamHandler = new PumpStreamHandler(stdout, stderr); DefaultExecutor executor = new DefaultExecutor(); executor.setStreamHandler(executeStreamHandler); int exitValue; try {/*from ww w. j a v a 2 s .c o m*/ exitValue = executor.execute(cmdLine); } catch (Exception e) { exitValue = -1; logger.warn("Error executing: {}", cmdLine, e); } CommandResult commandResult = new CommandResult(cmdLine.toString(), exitValue, stdout.toString(), stderr.toString()); this.stdout = stdout.toString(); logger.debug("Finished executing: {}", commandResult); return commandResult; } }
From source file:com.arhs.mojo.pack200.AbstractPluginMojo.java
/** * Constructor./*from w w w . j a v a 2 s .c o m*/ * * @param command Command name. */ protected AbstractPluginMojo(String command) { this(CommandLine.parse(command), new DefaultExecutor()); }
From source file:com.k42b3.aletheia.filter.response.Application.java
public void exec(Response response) throws Exception { if (response instanceof com.k42b3.aletheia.protocol.http.Response) { com.k42b3.aletheia.protocol.http.Response httpResponse = (com.k42b3.aletheia.protocol.http.Response) response; String contentType = httpResponse.getHeader("Content-Type"); if (Aletheia.getInstance().getConfig().getApplications().containsKey(contentType)) { String path = Aletheia.getInstance().getConfig().getApplications().get(contentType); String url = Aletheia.getInstance().getActiveUrl().getText(); String cmd = path.replace("${url}", url); try { logger.info("Call " + cmd); CommandLine commandLine = CommandLine.parse(cmd); DefaultExecutor executor = new DefaultExecutor(); executor.execute(commandLine); } catch (Exception e) { Aletheia.handleException(e); }/*from w w w.j av a2 s . c o m*/ } } }
From source file:de.akquinet.innovation.play.maven.Play2TestMojo.java
public void execute() throws MojoExecutionException { if (isSkipExecution()) { getLog().info("Test phase skipped"); return;/*from w ww . ja va 2 s .c o m*/ } String line = getPlay2().getAbsolutePath(); CommandLine cmdLine = CommandLine.parse(line); cmdLine.addArguments(getPlay2SystemPropertiesArguments(), false); cmdLine.addArgument("test"); DefaultExecutor executor = new DefaultExecutor(); if (timeout > 0) { ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout); executor.setWatchdog(watchdog); } executor.setWorkingDirectory(project.getBasedir()); executor.setExitValue(0); try { executor.execute(cmdLine, getEnvironment()); } catch (IOException e) { if (testFailureIgnore) { getLog().error("Test execution failures ignored"); } else { throw new MojoExecutionException("Error during compilation", e); } } }
From source file:at.medevit.elexis.gdt.handler.GDTOutputHandler.java
public static void handleOutput(GDTSatzNachricht gdtSatzNachricht, IGDTCommunicationPartner cp) { int connectionType = cp.getConnectionType(); switch (connectionType) { case SystemConstants.FILE_COMMUNICATION: boolean success = GDTFileHelper.writeGDTSatzNachricht(gdtSatzNachricht, cp); if (success) { GDTProtokoll.addEntry(GDTProtokoll.MESSAGE_DIRECTION_OUT, cp, gdtSatzNachricht); } else {//from w w w. ja va2 s . co m String message = "Fehler beim Schreiben der GDT Satznachricht " + gdtSatzNachricht.getValue(GDTConstants.FELDKENNUNG_SATZIDENTIFIKATION) + " auf " + cp.getLabel(); Status status = new Status(IStatus.WARNING, Activator.PLUGIN_ID, message); StatusManager.getManager().handle(status, StatusManager.SHOW); logger.log(message, Log.WARNINGS); } // Update the protokoll view final IViewPart protokoll = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() .findView(GDTProtokollView.ID); Display display = PlatformUI.getWorkbench().getDisplay(); display.asyncExec(new Runnable() { @Override public void run() { if (protokoll != null) protokoll.setFocus(); } }); // Call the external program to care for the output (if applicable) String handlerProgram = cp.getExternalHandlerProgram(); if (handlerProgram != null) { CommandLine cmdLine = CommandLine.parse(handlerProgram); try { DefaultExecutor executor = new DefaultExecutor(); executor.setExitValues(null); // Ignore the exit value int exitValue = executor.execute(cmdLine); logger.log("Return value of " + cmdLine + ": " + exitValue, Log.DEBUGMSG); } catch (ExecuteException e) { String message = "Fehler beim Ausfhren von " + cmdLine; Status status = new Status(IStatus.WARNING, Activator.PLUGIN_ID, message, e); StatusManager.getManager().handle(status, StatusManager.SHOW); logger.log(e, message, Log.ERRORS); } catch (IOException e) { String message = "Fehler beim Ausfhren von " + cmdLine; Status status = new Status(IStatus.WARNING, Activator.PLUGIN_ID, message, e); StatusManager.getManager().handle(status, StatusManager.SHOW); logger.log(e, message, Log.ERRORS); } } break; case SystemConstants.SERIAL_COMMUNICATION: // TODO Serial output implementation break; default: break; } }
From source file:adb4j.executor.CmdExecutor.java
private CmdResultHandler runAsync(String command, CmdResultHandler resultHandler, boolean shouldClone) throws IOException, IOException, IOException, IOException { CmdResultHandler handler = shouldClone ? resultHandler.clone() : resultHandler; PumpStreamHandler streamHandler = handler.getStreamHandler(this); Executor executor = new DefaultExecutor(); executor.setStreamHandler(streamHandler); // String[] arguments = CommandLine.parse(command).toStrings(); // CommandLine cmdLine = new CommandLine(arguments[0]); // for (int i = 1; i < arguments.length; i++) { // cmdLine.addArgument(command, true); // }/*from w w w. j ava 2 s . c om*/ CommandLine cmdLine = CommandLine.parse(command); executor.execute(cmdLine, getEnvironment(), handler.delegate); return handler; }
From source file:io.vertx.config.vault.utils.VaultProcess.java
private void init() { String line = executable.getAbsolutePath() + " init -key-shares=1 -key-threshold=1 " + CA_CERT_ARG; System.out.println(">> " + line); CommandLine parse = CommandLine.parse(line); DefaultExecutor executor = new DefaultExecutor(); PumpStreamHandler pump = new PumpStreamHandler(new VaultOutputStream().addExtractor(l -> { if (l.contains("Unseal Key 1:")) { unseal = l.replace("Unseal Key 1: ", "").trim(); } else if (l.contains("Initial Root Token:")) { token = l.replace("Initial Root Token: ", "").trim(); }//ww w.j av a2s . co m }), System.err); ExecuteWatchdog watchDog = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT); executor.setWatchdog(watchDog); executor.setStreamHandler(pump); try { executor.execute(parse); } catch (IOException e) { throw new RuntimeException(e); } // await().until(() -> token != null); // await().until(() -> unseal != null); System.out.println("Vault Server initialized (but sealed)"); System.out.println("Root token: " + token); System.out.println("Unseal key: " + unseal); }
From source file:com.meltmedia.cadmium.blackbox.test.CliCommitCloneTest.java
/** * <p>Runs the Cadmium CLI command commit from Apache Commons Exec library. Then uses {@link CadmiumAssertions#assertContentDeployed(String, java.io.File, String)} to assert that the content deployed properly.</p> * <p>To override the site url, pass <code>-Dcom.meltmedia.cadmium.test.site.url=[URL]</code> to the jvm that this test case will be running in. The site url defaults to <code>http://localhost</code> if not set.</p> * @throws IOException See {@link DefaultExecutor#execute(CommandLine)} for more information. * @throws ExecuteException See {@link DefaultExecutor#execute(CommandLine)} for more information. * @throws InterruptedException /*w ww . j av a 2s . c om*/ * * @see <a href="http://commons.apache.org/exec">Apache Commons Exec</a> */ @Test public void testCommit() throws ExecuteException, IOException { String deployUrl = System.getProperty("com.meltmedia.cadmium.test.site.url", DEPLOY_URL); CommandLine commitCmd = CommandLine .parse("cadmium commit -m \"Testing commit command\" " + TEST_CONTENT_LOCATION + " " + deployUrl); DefaultExecutor exec = new DefaultExecutor(); exec.setExitValue(0); ExecuteWatchdog watchDog = new ExecuteWatchdog(60000); exec.setWatchdog(watchDog); int exitValue = exec.execute(commitCmd); assertEquals("Commit command returned with an error status.", exitValue, 0); assertContentDeployed("Failed to commit content to remote site.", new File(TEST_CONTENT_LOCATION), DEPLOY_URL); }
From source file:com.github.shyiko.hmp.StopMojo.java
private void kill(int pid) throws IOException { Executor executor = new DefaultExecutor(); executor.setStreamHandler(new ExecutionStreamHandler(quiet)); executor.execute(CommandLine.parse("kill -15 " + pid)); }