本文整理汇总了Java中org.apache.commons.exec.DefaultExecuteResultHandler.getExitValue方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultExecuteResultHandler.getExitValue方法的具体用法?Java DefaultExecuteResultHandler.getExitValue怎么用?Java DefaultExecuteResultHandler.getExitValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.exec.DefaultExecuteResultHandler
的用法示例。
在下文中一共展示了DefaultExecuteResultHandler.getExitValue方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}
}
示例3: 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;
}
}
示例4: 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()));
}
示例5: 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;
}
}
示例6: 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!");
}