List of usage examples for org.apache.commons.exec CommandLine CommandLine
public CommandLine(final CommandLine other)
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/* w ww . j a v a 2 s . c om*/ 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 w w w . j av a2 s . com if (tblout_ != null) { command.addArgument(" --tblout " + tblout_.getAbsolutePath()); } command.addArgument(cmfile_.getAbsolutePath()); command.addArgument(seqdb_.getAbsolutePath()); getShell().execute(command); }
From source file:org.excalibur.service.aws.CommandExample.java
public static void main(String[] args) throws ExecuteException, IOException, InterruptedException { CommandLine command = new CommandLine("/bin/bash"); command.addArgument("-c", false); command.addArgument("iperf3 -t 30 -c iperf.scottlinux.com >> output.txt", false); //Process process = Runtime.getRuntime().exec(new String[]{"bash", "-c", "iperf3 -t 60 -c localhost"}); // System.out.println(new Mirror().on(process).get().field("pid")); //process.waitFor(); // System.out.println(process.exitValue()); // ManagementFactory.getRuntimeMXBean().getName(); // System.out.println(IOUtils.readLines(process.getInputStream())); //String command = "iperf3 -t 30 -c iperf.scottlinux.com"; ExecuteWatchdog watchdog = new ExecuteWatchdog(10); final DefaultExecutor executor = new DefaultExecutor(); executor.setStreamHandler(new PumpStreamHandler()); executor.setExitValue(1);//from ww w . ja v a 2 s. c o m executor.execute(command, new ExecuteResultHandler() { @Override public void onProcessFailed(ExecuteException e) { e.printStackTrace(); } @Override public void onProcessComplete(int exitValue) { System.out.println(exitValue); } }); }
From source file:org.excalibur.service.compute.executor.Worker.java
public void execute(final Application application, ExecuteResultHandler executeResultHandler) throws ExecuteException, IOException { final String commandLine = application.getExecutableCommandLine(); DefaultExecutor executor = new DefaultExecutor(); CommandLine command = new CommandLine("/bin/sh"); command.addArgument("-c", false); command.addArgument(commandLine, false); executor.execute(command, System.getenv(), executeResultHandler); LOG.debug("Launched the execution of task: [{}], uuid: [{}]", commandLine, application.getId()); }
From source file:org.fornax.toolsupport.sculptor.maven.plugin.GeneratorMojo.java
/** * Builds command line for starting the Eclipse MWE2 launcher in a JVM. * // ww w .j a v a2 s .c o m * @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 w w w .j ava2 s.co 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; }
From source file:org.fuin.esmp.EventStoreDownloadMojo.java
private void applyFileMode(final File file, final FileMode fileMode) throws MojoExecutionException { if (OS.isFamilyUnix() || OS.isFamilyMac()) { final String smode = fileMode.toChmodStringFull(); final CommandLine cmdLine = new CommandLine("chmod"); cmdLine.addArgument(smode);/* w ww . ja v a2s .c o m*/ cmdLine.addArgument(file.getAbsolutePath()); final Executor executor = new DefaultExecutor(); try { final int result = executor.execute(cmdLine); if (result != 0) { throw new MojoExecutionException("Error # " + result + " while trying to set mode \"" + smode + "\" for file: " + file.getAbsolutePath()); } } catch (final IOException ex) { throw new MojoExecutionException( "Error while trying to set mode \"" + smode + "\" for file: " + file.getAbsolutePath(), ex); } } else { file.setReadable(fileMode.isUr() || fileMode.isGr() || fileMode.isOr()); file.setWritable(fileMode.isUw() || fileMode.isGw() || fileMode.isOw()); file.setExecutable(fileMode.isUx() || fileMode.isGx() || fileMode.isOx()); } }
From source file:org.fuin.esmp.EventStorePostStartMojo.java
@Override protected final void executeGoal() throws MojoExecutionException { if (postStartCommand == null) { throw new MojoExecutionException("postStartCommand not set"); }//from w w w . j a v a 2 s . co m LOG.info("postStartCommand={}", postStartCommand); final CommandLine cmdLine = new CommandLine(postStartCommand); final DefaultExecutor executor = new DefaultExecutor(); try { final ByteArrayOutputStream bos = new ByteArrayOutputStream(); final PumpStreamHandler psh = new PumpStreamHandler(bos); executor.setStreamHandler(psh); executor.setWorkingDirectory(getEventStoreDir()); final int exitCode = executor.execute(cmdLine); messages = asList(bos.toString()); if (exitCode == 0) { LOG.info("Post-start command executed successfully"); logDebug(messages); } else { LOG.error("Post-start command failed with exit code: {}", exitCode); logError(messages); } } catch (final IOException ex) { throw new MojoExecutionException("Error executing the command line: " + cmdLine, ex); } }
From source file:org.fuin.esmp.EventStoreStartMojo.java
private CommandLine createCommandLine() throws MojoExecutionException { final CommandLine cmdLine = new CommandLine(command); if (arguments != null) { for (final String argument : arguments) { cmdLine.addArgument(argument); }//from w w w. j a v a2 s . c o m } return cmdLine; }
From source file:org.fuin.esmp.EventStoreStopMojo.java
private CommandLine createCommandLine() throws MojoExecutionException { final CommandLine cmdLine = new CommandLine(command); if (OS.isFamilyWindows()) { cmdLine.addArgument("/PID"); cmdLine.addArgument(readPid());//w ww.jav a2s .c o m cmdLine.addArgument("/F"); } else if (OS.isFamilyUnix() || OS.isFamilyMac()) { cmdLine.addArgument("-SIGKILL"); cmdLine.addArgument(readPid()); } else { throw new MojoExecutionException("Unknown OS - Cannot kill the process"); } return cmdLine; }