List of usage examples for org.apache.commons.exec CommandLine addArgument
public CommandLine addArgument(final String argument)
From source file:org.docwhat.iated.AppState.java
public String editFile(File file) { String editor = getEditor();/* ww w . j a v a2 s .c o m*/ CommandLine cmd; if (OS.isFamilyMac() && editor.matches(".*\\.app")) { cmd = new CommandLine("/usr/bin/open"); cmd.addArgument("-a").addArgument(editor).addArgument(file.toString()); } else { cmd = new CommandLine(editor); cmd.addArgument(file.toString()); } Executor executor = new DefaultExecutor(); try { executor.execute(cmd); } catch (ExecuteException ex) { //TODO Do something meaningful with the exception. throw new RuntimeException(ex); } catch (IOException ex) { //TODO Do something meaningful with the exception. throw new RuntimeException(ex); } return "bogus-token"; }
From source file:org.eclipse.php.composer.core.launch.environment.SysPhpPrjPhar.java
public CommandLine getCommand() { CommandLine cmd = new CommandLine(php.trim()); // specify php.ini location File iniFile = PHPINIUtil.findPHPIni(php); if (iniFile != null) { cmd.addArgument("-c"); //$NON-NLS-1$ cmd.addArgument(iniFile.getAbsolutePath()); }/* www . j a v a2 s. co m*/ // specify composer.phar location cmd.addArgument(phar.trim()); return cmd; }
From source file:org.eclipse.php.composer.core.launch.environment.SysPhpSysPhar.java
public CommandLine getCommand() { CommandLine cmd = new CommandLine(php.trim()); cmd.addArgument(phar.trim()); return cmd; }
From source file:org.eclipse.php.composer.core.launch.ScriptLauncher.java
public void launch(String argument, String[] params) throws ExecuteException, IOException, InterruptedException { CommandLine cmd = environment.getCommand(); cmd.addArgument(argument); cmd.addArguments(params);//from w ww.j a v a 2 s . c o m executor = new ScriptExecutor(); if (timeout != null) { executor.setTimeout(timeout); } Logger.debug("Setting executor working directory to " + project.getLocation().toOSString()); //$NON-NLS-1$ executor.setWorkingDirectory(project.getLocation().toFile()); for (ExecutionResponseListener listener : listeners) { executor.addResponseListener(listener); } Map<String, String> env = new HashMap<String, String>(System.getenv()); PHPLaunchUtilities.appendExecutableToPathEnv(env, new File(cmd.getExecutable()).getParentFile()); PHPLaunchUtilities.appendLibrarySearchPathEnv(env, new File(cmd.getExecutable()).getParentFile()); executor.execute(cmd, env); }
From source file:org.eclipse.php.composer.ui.preferences.launcher.ExecutableTester.java
@Override public void run() { try {//from ww w . j a v a 2 s. c o m ScriptExecutor executor = new ScriptExecutor(); CommandLine cmd = new CommandLine(phPexeItem.getExecutable()); cmd.addArgument("testexecutable"); //$NON-NLS-1$ Bundle bundle = Platform.getBundle(ComposerUIPlugin.PLUGIN_ID); URL entry = bundle.getEntry("Resources/launcher"); //$NON-NLS-1$ File file = new File(FileLocator.resolve(entry).toURI()); if (file != null) { executor.setWorkingDirectory(file); } executor.addResponseListener(listener); executor.execute(cmd); } catch (Exception e) { Logger.logException(e); } }
From source file:org.eclipse.php.composer.ui.terminal.ComposerLauncher.java
@Override public void launch(String argument, String... params) throws ExecuteException, IOException, InterruptedException { CommandLine cmd = environment.getCommand(); cmd.addArgument(argument); cmd.addArguments(params);//from w w w . j a v a2 s .c o m Map<String, String> env = new HashMap<String, String>(System.getenv()); PHPLaunchUtilities.appendExecutableToPathEnv(env, new File(cmd.getExecutable()).getParentFile()); PHPLaunchUtilities.appendLibrarySearchPathEnv(env, new File(cmd.getExecutable()).getParentFile()); Map<String, Object> properties = new HashMap<String, Object>(); List<String> envs = new ArrayList<>(env.size()); for (String key : env.keySet()) { envs.add(key + '=' + env.get(key)); } properties.put(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT, envs.toArray(new String[envs.size()])); properties.put(ITerminalsConnectorConstants.PROP_PROCESS_MERGE_ENVIRONMENT, true); ITerminalServiceOutputStreamMonitorListener[] outListeners = new ITerminalServiceOutputStreamMonitorListener[] { new ITerminalServiceOutputStreamMonitorListener() { @Override public void onContentReadFromStream(byte[] byteBuffer, int bytesRead) { for (ExecutionResponseListener handler : getListeners()) { handler.executionMessage(new String(byteBuffer, 0, bytesRead)); } } } }; properties.put(ITerminalsConnectorConstants.PROP_STDOUT_LISTENERS, outListeners); // workaround for colored output on Windows if (Platform.OS_WIN32.equals(Platform.getOS())) { StringBuilder builder = new StringBuilder(); builder.append("@echo off").append(WINDOWS_END_OF_LINE); // $NON-NLS-1$ // 65001 - UTF-8 builder.append("chcp 65001").append(WINDOWS_END_OF_LINE); // $NON-NLS-1$ builder.append("cls").append(WINDOWS_END_OF_LINE); //$NON-NLS-1$ builder.append(escapePath(cmd.getExecutable())).append(' '); for (String arg : cmd.getArguments()) { builder.append(arg).append(' '); } File file = File.createTempFile("composer_windows_", ".bat"); // $NON-NLS-1$ //$NON-NLS-2$ file.deleteOnExit(); try (BufferedWriter writer = new BufferedWriter(new FileWriter(file));) { writer.write(builder.toString()); } catch (FileNotFoundException ex) { ComposerPlugin.logException(ex); } properties.put(ITerminalsConnectorConstants.PROP_PROCESS_PATH, "cmd"); //$NON-NLS-1$ String args = "/C " + file.getAbsolutePath(); //$NON-NLS-1$ properties.put(ITerminalsConnectorConstants.PROP_PROCESS_ARGS, args); } else { properties.put(ITerminalsConnectorConstants.PROP_PROCESS_PATH, escapePath(cmd.getExecutable())); StringBuilder builder = new StringBuilder(); for (String arg : cmd.getArguments()) { builder.append(arg + ' '); } properties.put(ITerminalsConnectorConstants.PROP_PROCESS_ARGS, builder.toString()); } Logger.debug("Setting executor working directory to " + project.getLocation().toOSString()); //$NON-NLS-1$ properties.put(ITerminalsConnectorConstants.PROP_PROCESS_WORKING_DIR, project.getLocation().toOSString()); String title = MessageFormat.format(Messages.ComposerConsoleManager_ConsoleLabel, Messages.ComposerConsoleManager_ConsoleName, project.getName()); IConsoleManager consoleManager = ConsolePlugin.getDefault().getConsoleManager(); final CountDownLatch latch = new CountDownLatch(1); terminalConsole = new TerminalConsole(title, 0, properties, new Done() { @Override public void done(IStatus status) { latch.countDown(); } }); for (ExecutionResponseListener handler : getListeners()) { handler.executionStarted(); } consoleManager.addConsoles(new IConsole[] { terminalConsole }); consoleManager.showConsoleView(terminalConsole); latch.await(); for (ExecutionResponseListener handler : getListeners()) { handler.executionFinished("", 0); //$NON-NLS-1$ } }
From source file:org.epics.archiverappliance.TomcatSetup.java
private void createAndStartTomcatInstance(String testName, final String applianceName, int port, int startupPort) throws IOException { File workFolder = makeTomcatFolders(testName, applianceName, port, startupPort); HashMap<String, String> environment = createEnvironment(testName, applianceName); File logsFolder = new File(workFolder, "logs"); assert (logsFolder.exists()); CommandLine cmdLine = new CommandLine( System.getenv("TOMCAT_HOME") + File.separator + "bin" + File.separator + "catalina.sh"); cmdLine.addArgument("run"); DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler(); final CountDownLatch latch = new CountDownLatch(1); PumpStreamHandler pump = new PumpStreamHandler(new LogOutputStream() { @Override//from w w w . j av a2s . co m protected void processLine(String msg, int level) { if (msg != null && msg.contains("All components in this appliance have started up")) { logger.info(applianceName + " has started up."); latch.countDown(); } System.out.println(msg); } }, System.err); ExecuteWatchdog watchdog = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT); Executor executor = new DefaultExecutor(); executor.setExitValue(1); executor.setWatchdog(watchdog); executor.setStreamHandler(pump); executor.setWorkingDirectory(logsFolder); executor.execute(cmdLine, environment, resultHandler); executorWatchDogs.add(watchdog); // We wait for some time to make sure the server started up try { latch.await(2, TimeUnit.MINUTES); } catch (InterruptedException ex) { } logger.info("Done starting tomcat for the testing."); }
From source file:org.excalibur.service.aws.CmsearchCommand.java
public void execute() throws ShellException, IOException { CommandLine command = new CommandLine("cmsearch"); if (output_ != null) { command.addArguments("-o " + output_.getAbsolutePath()); }//from ww w. j a v a2s .c o m if (tblout_ != null) { command.addArgument(" --tblout " + tblout_.getAbsolutePath()); } command.addArgument(cmfile_.getAbsolutePath()); command.addArgument(seqdb_.getAbsolutePath()); getShell().execute(command); }
From source file:org.fornax.toolsupport.sculptor.maven.plugin.GeneratorMojo.java
/** * Builds command line for starting the Eclipse MWE2 launcher in a JVM. * /*from w w w . jav a 2s .c om*/ * @param changedFiles * list of files from <code>checkFileSets</code> which are * modified since last generator execution or <code>null</code> * if code generation is enforced */ protected CommandLine getGeneratorCommandLine(Set<String> changedFiles) throws MojoExecutionException { CommandLine cl = new CommandLine(getJavaExecutable()); cl.addArguments(jvmArguments); if (changedFiles != null) { cl.addArgument("-D" + CHANGED_FILES_PROPERTY + "=" + toCommaSeparatedString(changedFiles)); } cl.addArgument("-D" + GeneratorMojo.LOGBACK_CONFIGURATION_FILE_PROPERTY + "=" + this.getClass().getResource("/" + (isVerbose() ? LOGBACK_VERBOSE_CONFIGURATION_FILE_NAME : LOGBACK_NORMAL_CONFIGURATION_FILE_NAME))); cl.addArguments("-classpath " + getGeneratorClasspath()); cl.addArgument(MWE2_WORKFLOW_LAUNCHER); cl.addArgument(workflowDescriptor); if (isVerbose() || getLog().isDebugEnabled()) { getLog().info("Commandline: " + cl); } return cl; }
From source file:org.fornax.toolsupport.sculptor.maven.plugin.GraphvizMojo.java
/** * Builds command line for starting the <code>dot</code>. * /*from ww w.ja v a 2 s .c o m*/ * @param generatedFiles * list of generated files from the * {@link AbstractSculptorMojo#statusFile} */ protected CommandLine getDotCommandLine(Set<String> generatedFiles) throws MojoExecutionException { CommandLine cl = new CommandLine(command); cl.addArgument("-q"); cl.addArgument("-Tpng"); cl.addArgument("-O"); for (String generatedFile : generatedFiles) { if (generatedFile.endsWith(".dot")) { cl.addArgument(generatedFile); } } if (isVerbose() || getLog().isDebugEnabled()) { getLog().info("Commandline: " + cl); } return cl; }