use of org.apache.commons.exec.DefaultExecutor in project BroadleafCommerce by BroadleafCommerce.
the class MvelHelperTest method executeExternalJavaProcess.
protected String executeExternalJavaProcess(Class<?> mainClass) throws IOException {
String classpath = MvelTestUtils.getClassPath();
// See javadoc on MvelOverloadFailureReproduction for description of why we need to execute the test in a new JVM
CommandLine cmdLine = new CommandLine("java");
cmdLine.addArgument("-cp");
cmdLine.addArgument(classpath, true);
cmdLine.addArgument(mainClass.getName());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Executor executor = new DefaultExecutor();
executor.setStreamHandler(new PumpStreamHandler(baos));
try {
executor.execute(cmdLine, new HashMap<String, String>());
} catch (IOException e) {
throw new IOException(new String(baos.toByteArray()));
}
return new String(baos.toByteArray());
}
use of org.apache.commons.exec.DefaultExecutor in project mule by mulesoft.
the class UnixController method getProcessId.
@Override
public int getProcessId() {
Map<Object, Object> newEnv = this.copyEnvironmentVariables();
DefaultExecutor executor = new DefaultExecutor();
ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout);
executor.setWatchdog(watchdog);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream);
executor.setStreamHandler(streamHandler);
if (this.doExecution(executor, new CommandLine(this.muleBin).addArgument("status"), newEnv) == 0) {
Matcher matcher = STATUS_PATTERN.matcher(outputStream.toString());
if (matcher.find()) {
return Integer.parseInt(matcher.group(3));
} else {
throw new MuleControllerException("bin/mule status didn't return the expected pattern: " + STATUS);
}
} else {
throw new MuleControllerException("Mule Runtime is not running");
}
}
use of org.apache.commons.exec.DefaultExecutor in project vertx-openshift-it by cescoffier.
the class OC method executeWithQuotes.
/**
* This method will look for the OC exec first, then execute a command constructed from <b>args</b> param.
* @param handleQuoting specifies whether to wrap arguments in quotation marks or not.
* @param args args from which the command will be constructed
* @return output of the executed command, wrapped in single quotation marks.
*/
public static String executeWithQuotes(boolean handleQuoting, String... args) {
File oc_executable = find();
CommandLine commandLine = new CommandLine(oc_executable);
commandLine.addArguments(args, handleQuoting);
DefaultExecutor executor = new DefaultExecutor();
try {
ByteArrayOutputStream output = new ByteArrayOutputStream();
PumpStreamHandler handler = new PumpStreamHandler(output);
executor.setStreamHandler(handler);
executor.setExitValues(new int[] { 0, 1, 2 });
executor.execute(commandLine);
if (!output.toString().isEmpty()) {
System.out.println("====");
System.out.println(output);
System.out.println("====");
}
return output.toString();
} catch (IOException e) {
throw new RuntimeException("Unable to execute " + commandLine.toString(), e);
}
}
use of org.apache.commons.exec.DefaultExecutor in project georocket by georocket.
the class ElasticsearchRunner method runElasticsearch.
/**
* Run Elasticsearch
* @param host the host Elasticsearch should bind to
* @param port the port Elasticsearch should listen on
* @param elasticsearchInstallPath the path where Elasticsearch is installed
* @return an observable that emits exactly one item when Elasticsearch has started
*/
public Observable<Void> runElasticsearch(String host, int port, String elasticsearchInstallPath) {
JsonObject config = vertx.getOrCreateContext().config();
String storage = config.getString(ConfigConstants.STORAGE_FILE_PATH);
String root = storage + "/index";
return vertx.<Void>rxExecuteBlocking(f -> {
log.info("Starting Elasticsearch ...");
// get Elasticsearch executable
String executable = FilenameUtils.separatorsToSystem(elasticsearchInstallPath);
executable = FilenameUtils.concat(executable, "bin");
if (SystemUtils.IS_OS_WINDOWS) {
executable = FilenameUtils.concat(executable, "elasticsearch.bat");
} else {
executable = FilenameUtils.concat(executable, "elasticsearch");
}
// start Elasticsearch
CommandLine cmdl = new CommandLine(executable);
cmdl.addArgument("-Ecluster.name=georocket-cluster");
cmdl.addArgument("-Enode.name=georocket-node");
cmdl.addArgument("-Enetwork.host=" + host);
cmdl.addArgument("-Ehttp.port=" + port);
cmdl.addArgument("-Epath.data=" + root + "/data");
executor = new DefaultExecutor();
executor.setProcessDestroyer(new ShutdownHookProcessDestroyer());
executor.setWatchdog(new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT));
// set ES_JAVA_OPTS environment variable if necessary
Map<String, String> env = new HashMap<>(System.getenv());
if (!env.containsKey("ES_JAVA_OPTS")) {
String javaOpts = config.getString(ConfigConstants.INDEX_ELASTICSEARCH_JAVA_OPTS);
if (javaOpts != null) {
env.put("ES_JAVA_OPTS", javaOpts);
}
}
try {
executor.execute(cmdl, env, new DefaultExecuteResultHandler() {
@Override
public void onProcessComplete(final int exitValue) {
log.info("Elasticsearch quit with exit code: " + exitValue);
}
@Override
public void onProcessFailed(final ExecuteException e) {
if (!stopped) {
log.error("Elasticsearch execution failed", e);
}
}
});
f.complete();
} catch (IOException e) {
f.fail(e);
}
}).toObservable();
}
use of org.apache.commons.exec.DefaultExecutor in project storm by apache.
the class ServerUtils method execCommand.
public static int execCommand(String... command) throws ExecuteException, IOException {
CommandLine cmd = new CommandLine(command[0]);
for (int i = 1; i < command.length; i++) {
cmd.addArgument(command[i]);
}
DefaultExecutor exec = new DefaultExecutor();
return exec.execute(cmd);
}
Aggregations