本文整理汇总了Java中org.apache.commons.exec.DefaultExecuteResultHandler类的典型用法代码示例。如果您正苦于以下问题:Java DefaultExecuteResultHandler类的具体用法?Java DefaultExecuteResultHandler怎么用?Java DefaultExecuteResultHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultExecuteResultHandler类属于org.apache.commons.exec包,在下文中一共展示了DefaultExecuteResultHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testExecutable
import org.apache.commons.exec.DefaultExecuteResultHandler; //导入依赖的package包/类
private static boolean testExecutable() {
CommandLine commandLine = CommandLine.parse(RCLIProcessor.rExecutable + " " + VERSION_CALL);
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
Executor executor = new DefaultExecutor();
// put a watchdog with a timeout
ExecuteWatchdog watchdog = new ExecuteWatchdog(new Long(TIMEOUT_SECONDS) * 1000);
executor.setWatchdog(watchdog);
try {
executor.execute(commandLine, resultHandler);
resultHandler.waitFor();
int exitVal = resultHandler.getExitValue();
if (exitVal != 0) {
return false;
}
return true;
}
catch (Exception e) {
return false;
}
}
示例2: run
import org.apache.commons.exec.DefaultExecuteResultHandler; //导入依赖的package包/类
public void run() {
try {
executor = new DaemonExecutor();
resultHandler = new DefaultExecuteResultHandler();
String javaHome = System.getProperty("java.home");
String userDir = System.getProperty("user.dir");
executor.setStreamHandler(new PumpStreamHandler(System.out));
watchdog = new ExecuteWatchdog(15000);
executor.setWatchdog(watchdog);
executor.execute(new CommandLine(javaHome + SystemUtils.FILE_SEPARATOR
+ "bin"+ SystemUtils.FILE_SEPARATOR+"java.exe").addArgument("-version"));
executor.execute(new CommandLine(javaHome + SystemUtils.FILE_SEPARATOR
+ "bin"+ SystemUtils.FILE_SEPARATOR+"java.exe")
.addArgument("-jar")
.addArgument(userDir + "/../moneta-springboot/target/moneta-springboot-" + ContractTestSuite.getProjectVersion() + ".jar"));
}
catch (Exception e) {
e.printStackTrace();
}
}
示例3: testExecutable
import org.apache.commons.exec.DefaultExecuteResultHandler; //导入依赖的package包/类
public static boolean testExecutable() {
CommandLine commandLine = CommandLine.parse(PythonCLIProcessor.pythonExecutable + " --version");
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
Executor executor = new DefaultExecutor();
// put a watchdog with a timeout
ExecuteWatchdog watchdog = new ExecuteWatchdog(new Long(timeout_seconds) * 1000);
executor.setWatchdog(watchdog);
try {
executor.execute(commandLine, resultHandler);
resultHandler.waitFor();
int exitVal = resultHandler.getExitValue();
if (exitVal != 0) {
return false;
}
return true;
}
catch (Exception e) {
return false;
}
}
示例4: dockerAsync
import org.apache.commons.exec.DefaultExecuteResultHandler; //导入依赖的package包/类
/**
* Runs docker command asynchronously.
*
* @param arguments command line arguments
* @param out stdout will be written in to this file
*
* @return a handle used to stop the command process
*
* @throws IOException when command has error
*/
public ExecuteWatchdog dockerAsync(final List<Object> arguments, OutputStream out) throws IOException {
CommandLine cmdLine = new CommandLine(DOCKER);
arguments.forEach((arg) -> {
cmdLine.addArgument(arg + "");
});
LOG.debug("[{} {}]", cmdLine.getExecutable(), StringUtils.join(cmdLine.getArguments(), " "));
List<String> output = new ArrayList<>();
ExecuteWatchdog watchdog = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT);
Executor executor = new DefaultExecutor();
executor.setWatchdog(watchdog);
PrintWriter writer = new PrintWriter(out);
ESH esh = new ESH(writer);
executor.setStreamHandler(esh);
executor.execute(cmdLine, new DefaultExecuteResultHandler());
return watchdog;
}
示例5: setUpBeforeClass
import org.apache.commons.exec.DefaultExecuteResultHandler; //导入依赖的package包/类
@BeforeClass
public static void setUpBeforeClass() throws Exception {
System.out.println("Java Temp Dir: " +System.getProperty("java.io.tmpdir"));
executor = new DefaultExecutor();
resultHandler = new DefaultExecuteResultHandler();
String javaHome = System.getProperty("java.home");
String userDir = System.getProperty("user.dir");
executor.setStreamHandler(new PumpStreamHandler(System.out));
watchdog = new ExecuteWatchdog(10000);
executor.setWatchdog(watchdog);
executor.execute(new CommandLine(javaHome + SystemUtils.FILE_SEPARATOR
+ "bin"+ SystemUtils.FILE_SEPARATOR+"java.exe").addArgument("-version"));
executor.execute(new CommandLine(javaHome + SystemUtils.FILE_SEPARATOR
+ "bin"+ SystemUtils.FILE_SEPARATOR+"java.exe")
.addArgument("-jar")
.addArgument(userDir + "/../moneta-dropwizard/target/moneta-dropwizard-" + ContractTestSuite.getProjectVersion() + ".jar")
.addArgument("server")
.addArgument("src/main/resources/dropwizard/moneta-dropwizard.yaml"), resultHandler);
Thread.sleep(3000);
System.out.println("Test sequence starting....");
}
示例6: execAsync
import org.apache.commons.exec.DefaultExecuteResultHandler; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
public static void execAsync(String display, CommandLine commandline)
throws ShellCommandException {
log.debug("executing async command: " + commandline);
DefaultExecutor exec = new DefaultExecutor();
ExecuteResultHandler handler = new DefaultExecuteResultHandler();
PumpStreamHandler streamHandler = new PumpStreamHandler(
new PritingLogOutputStream());
exec.setStreamHandler(streamHandler);
try {
if (display == null || display.isEmpty()) {
exec.execute(commandline, handler);
} else {
Map env = EnvironmentUtils.getProcEnvironment();
EnvironmentUtils.addVariableToEnvironment(env, "DISPLAY=:"
+ display);
exec.execute(commandline, env, handler);
}
} catch (Exception e) {
throw new ShellCommandException(
"An error occured while executing shell command: "
+ commandline, e);
}
}
示例7: getVersion
import org.apache.commons.exec.DefaultExecuteResultHandler; //导入依赖的package包/类
public static String getVersion() {
try {
URL scriptURL = PythonCLIProbe.class.getResource(versionScriptFile);
File sf = new File(scriptURL.toURI());
String scriptPath = sf.getAbsolutePath();
CommandLine commandLine = CommandLine.parse(PythonCLIProcessor.pythonExecutable + " " + scriptPath);
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
Executor executor = new DefaultExecutor();
// put a watchdog with a timeout
ExecuteWatchdog watchdog = new ExecuteWatchdog(new Long(timeout_seconds) * 1000);
executor.setWatchdog(watchdog);
ByteArrayOutputStream os = new ByteArrayOutputStream();
PumpStreamHandler psh = new PumpStreamHandler(os);
executor.setStreamHandler(psh);
executor.execute(commandLine, resultHandler);
resultHandler.waitFor();
int exitVal = resultHandler.getExitValue();
if (exitVal != 0) {
return null;
}
return (os.toString());
}
catch (Exception e) {
return null;
}
}
示例8: executeGoal
import org.apache.commons.exec.DefaultExecuteResultHandler; //导入依赖的package包/类
@Override
protected final void executeGoal() throws MojoExecutionException {
init();
LOG.info("command={}", command);
LOG.info("arguments={}", Arrays.toString(arguments));
final CommandLine cmdLine = createCommandLine();
final DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
final DaemonExecutor executor = new DaemonExecutor();
try {
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
final PumpStreamHandler psh = new PumpStreamHandler(bos);
executor.setStreamHandler(psh);
executor.setWorkingDirectory(getEventStoreDir());
executor.execute(cmdLine, resultHandler);
final List<String> messages = waitForHttpServer(resultHandler, bos);
logDebug(messages);
final String pid = extractPid(messages);
LOG.info("Event store process ID: {}", pid);
writePid(pid);
} catch (final IOException ex) {
throw new MojoExecutionException(
"Error executing the command line: " + cmdLine, ex);
}
}
示例9: learn
import org.apache.commons.exec.DefaultExecuteResultHandler; //导入依赖的package包/类
public static void learn(String path, String factsForLearningFile,
String rulesDefinitionFile, String learnedWeightsFile)
throws Exception {
CommandLine cmdLine = new CommandLine(path + "/learnwts");
cmdLine.addArgument("-i");
cmdLine.addArgument(factsForLearningFile);
cmdLine.addArgument("-o");
cmdLine.addArgument(rulesDefinitionFile);
cmdLine.addArgument("-t");
cmdLine.addArgument(learnedWeightsFile);
cmdLine.addArgument("-g -multipleDatabases");
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
ExecuteWatchdog watchdog = new ExecuteWatchdog(60 * 1000);
Executor executor = new DefaultExecutor();
executor.setExitValue(1);
executor.setWatchdog(watchdog);
executor.execute(cmdLine, resultHandler);
resultHandler.waitFor();
}
示例10: startAppiumServer
import org.apache.commons.exec.DefaultExecuteResultHandler; //导入依赖的package包/类
private void startAppiumServer() {
try {
// Kill any node servers that may be running
stopAppiumServer();
log.info("START APPIUM");
CommandLine command = new CommandLine(ConfigurationManager.getInstance().getMobileAppiumNodeServerCommandLine());
for (String argument : ConfigurationManager.getInstance().getMobileAppiumNodeServerArguments()) {
command.addArgument(argument);
}
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(1);
executor.execute(command, resultHandler);
Thread.sleep(10000);
log.info("APPIUM server started successfully.");
} catch (IOException e) {
log.error("Appium Server Failed to start.", e);
} catch (InterruptedException ie) {
log.error("Appium Server wait failed.", ie);
}
}
示例11: executeCommand
import org.apache.commons.exec.DefaultExecuteResultHandler; //导入依赖的package包/类
private Future<CommandResult> executeCommand(String command, File executionDirectory, boolean silent)
throws IOException {
StringWriter writer = new StringWriter();
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
try (WriterOutputStream outputStream = new WriterOutputStream(writer)) {
String outerCommand = "/bin/bash -lc";
CommandLine outer = CommandLine.parse(outerCommand);
outer.addArgument(command, false);
DefaultExecutor executor = new DefaultExecutor();
executor.setWorkingDirectory(executionDirectory);
executor.setStreamHandler(new PumpStreamHandler(silent ? outputStream : System.out, null));
executor.execute(outer, ENVIRONMENT, resultHandler);
resultHandler.waitFor();
} catch (InterruptedException e) {
throw new IllegalStateException(e);
}
return new AsyncResult<CommandResult>(
new CommandResult(resultHandler.getExitValue(), writer.toString(), resultHandler.getException()));
}
示例12: executeCommandUsingApacheExec
import org.apache.commons.exec.DefaultExecuteResultHandler; //导入依赖的package包/类
/**
* Execute a command on the operating system using Apache Commons Exec. This
* function runs asynchronously and dumps both stderr and stdout streams to
* a temp file.
*
* @param commandLine The command to be executed.
* @param outputStreamHandler An output stream to dump the process stderr
* and stdout to it.
*/
public static void executeCommandUsingApacheExec(CommandLine commandLine, OutputStream outputStreamHandler) {
try {
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
PumpStreamHandler streamHandler = new PumpStreamHandler(outputStreamHandler);
Executor process = new DefaultExecutor();
process.setExitValue(0);
process.setStreamHandler(streamHandler);
process.execute(commandLine, resultHandler);
} catch (Exception ex) {
LOGGER.log(Level.SEVERE, "An exception was thrown.", ex);
}
}
示例13: start
import org.apache.commons.exec.DefaultExecuteResultHandler; //导入依赖的package包/类
public void start() throws Exception {
CommandLine cmdLine = new CommandLine(p4d);
// cmdLine.addArgument("-vserver=5");
cmdLine.addArgument("-C1");
cmdLine.addArgument("-r");
cmdLine.addArgument(formatPath(p4root.getAbsolutePath()));
cmdLine.addArgument("-p");
cmdLine.addArgument(p4port);
cmdLine.addArgument("-Llog");
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
DefaultExecutor executor = new DefaultExecutor();
executor.execute(cmdLine, resultHandler);
logger.info("start signal sent...");
P4PasswordImpl auth = new P4PasswordImpl(CredentialsScope.SYSTEM, "id",
"desc", p4port, null, "admin", "0", "Password");
int retry = 0;
while (retry < 20) {
try {
p4 = new ConnectionHelper(auth);
break;
} catch (Exception e) {
Thread.sleep(100);
}
}
}
示例14: getVersion
import org.apache.commons.exec.DefaultExecuteResultHandler; //导入依赖的package包/类
private static String getVersion() {
try {
CommandLine commandLine = CommandLine.parse(RCLIProcessor.rExecutable + " " + VERSION_CALL);
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
Executor executor = new DefaultExecutor();
// put a watchdog with a timeout
ExecuteWatchdog watchdog = new ExecuteWatchdog(new Long(TIMEOUT_SECONDS) * 1000);
executor.setWatchdog(watchdog);
ByteArrayOutputStream os = new ByteArrayOutputStream();
PumpStreamHandler psh = new PumpStreamHandler(os);
executor.setStreamHandler(psh);
executor.execute(commandLine, resultHandler);
resultHandler.waitFor();
int exitVal = resultHandler.getExitValue();
if (exitVal != 0) {
return null;
}
String osString = os.toString();
String versionString = osString.substring(osString.lastIndexOf(": ") + 2);
versionString = versionString.substring(0, versionString.indexOf('\n'));
return (versionString);
}
catch (Exception e) {
LOGGER.error("Could not get version string.", e);
return null;
}
}
示例15: waitForHttpServer
import org.apache.commons.exec.DefaultExecuteResultHandler; //导入依赖的package包/类
private List<String> waitForHttpServer(
final DefaultExecuteResultHandler resultHandler,
final ByteArrayOutputStream bos) throws MojoExecutionException {
// Wait for result
int wait = 0;
while ((wait++ < maxWaitCycles) && !resultHandler.hasResult()
&& !bos.toString().contains(upMessage)) {
sleep(sleepMs);
}
if (bos.toString().contains(upMessage)) {
// Success
return asList(bos.toString());
}
// Failure
final List<String> messages = asList(bos.toString());
logError(messages);
// Exception
if (resultHandler.hasResult()) {
throw new MojoExecutionException(
"Error starting the server. Exit code="
+ resultHandler.getExitValue(),
resultHandler.getException());
}
// Timeout
throw new MojoExecutionException(
"Waited too long for the server to start!");
}