本文整理汇总了Java中org.apache.commons.exec.DefaultExecuteResultHandler.waitFor方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultExecuteResultHandler.waitFor方法的具体用法?Java DefaultExecuteResultHandler.waitFor怎么用?Java DefaultExecuteResultHandler.waitFor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.exec.DefaultExecuteResultHandler
的用法示例。
在下文中一共展示了DefaultExecuteResultHandler.waitFor方法的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: 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();
}
示例5: 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()));
}
示例6: 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;
}
}