本文整理汇总了Java中org.apache.commons.exec.ExecuteException类的典型用法代码示例。如果您正苦于以下问题:Java ExecuteException类的具体用法?Java ExecuteException怎么用?Java ExecuteException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ExecuteException类属于org.apache.commons.exec包,在下文中一共展示了ExecuteException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: call
import org.apache.commons.exec.ExecuteException; //导入依赖的package包/类
@Override
public Long call() throws Exception {
Executor executor = new DefaultExecutor();
executor.setProcessDestroyer(new ShutdownHookProcessDestroyer());
ExecuteWatchdog watchDog = new ExecuteWatchdog(watchdogTimeout);
executor.setWatchdog(watchDog);
executor.setStreamHandler(new PumpStreamHandler(new MyLogOutputStream(handler, true), new MyLogOutputStream(handler, false)));
Long exitValue;
try {
exitValue = new Long(executor.execute(commandline));
} catch (ExecuteException e) {
exitValue = new Long(e.getExitValue());
}
if (watchDog.killedProcess()) {
exitValue = WATCHDOG_EXIST_VALUE;
}
return exitValue;
}
示例2: getBearSettings
import org.apache.commons.exec.ExecuteException; //导入依赖的package包/类
private static ArrayList<String> getBearSettings(String bearName)
throws ExecuteException, IOException {
JSONArray bearList = getAvailableBears();
JSONObject bear = null;
for (int i = 0; i < bearList.length(); i++) {
if (bearList.getJSONObject(i).getString("name").equals(bearName)) {
bear = bearList.getJSONObject(i);
break;
}
}
JSONArray nonOptionalParams = bear.getJSONObject("metadata")
.getJSONArray("non_optional_params");
ArrayList<String> settings = new ArrayList<>();
for (int i = 0; i < nonOptionalParams.length(); i++) {
JSONObject setting = nonOptionalParams.getJSONObject(i);
String key = setting.keys().next();
String userInput = DialogUtils.getInputDialog(key, setting.getString(key));
settings.add(key + "=" + userInput);
}
return settings;
}
示例3: handle
import org.apache.commons.exec.ExecuteException; //导入依赖的package包/类
@Override
public Map<String,Object> handle (Task aTask) throws Exception {
CommandLine cmd = new CommandLine ("mediainfo");
cmd.addArgument(aTask.getRequiredString("input"));
log.debug("{}",cmd);
DefaultExecutor exec = new DefaultExecutor();
File tempFile = File.createTempFile("log", null);
try (PrintStream stream = new PrintStream(tempFile);) {
exec.setStreamHandler(new PumpStreamHandler(stream));
exec.execute(cmd);
return parse(FileUtils.readFileToString(tempFile));
}
catch (ExecuteException e) {
throw new ExecuteException(e.getMessage(),e.getExitValue(), new RuntimeException(FileUtils.readFileToString(tempFile)));
}
finally {
FileUtils.deleteQuietly(tempFile);
}
}
示例4: handle
import org.apache.commons.exec.ExecuteException; //导入依赖的package包/类
@Override
public Object handle(Task aTask) throws Exception {
List<String> options = aTask.getList("options", String.class);
CommandLine cmd = new CommandLine ("ffmpeg");
options.forEach(o->cmd.addArgument(o));
log.debug("{}",cmd);
DefaultExecutor exec = new DefaultExecutor();
File tempFile = File.createTempFile("log", null);
try (PrintStream stream = new PrintStream(tempFile);) {
exec.setStreamHandler(new PumpStreamHandler(stream));
int exitValue = exec.execute(cmd);
return exitValue!=0?FileUtils.readFileToString(tempFile):cmd.toString();
}
catch (ExecuteException e) {
throw new ExecuteException(e.getMessage(),e.getExitValue(), new RuntimeException(FileUtils.readFileToString(tempFile)));
}
finally {
FileUtils.deleteQuietly(tempFile);
}
}
示例5: handle
import org.apache.commons.exec.ExecuteException; //导入依赖的package包/类
@Override
public Map<String,Object> handle(Task aTask) throws Exception {
CommandLine cmd = new CommandLine ("ffprobe");
cmd.addArgument("-v")
.addArgument("quiet")
.addArgument("-print_format")
.addArgument("json")
.addArgument("-show_error")
.addArgument("-show_format")
.addArgument("-show_streams")
.addArgument(aTask.getRequiredString("input"));
log.debug("{}",cmd);
DefaultExecutor exec = new DefaultExecutor();
File tempFile = File.createTempFile("log", null);
try (PrintStream stream = new PrintStream(tempFile);) {
exec.setStreamHandler(new PumpStreamHandler(stream));
exec.execute(cmd);
return parse(FileUtils.readFileToString(tempFile));
}
catch (ExecuteException e) {
throw new ExecuteException(e.getMessage(),e.getExitValue(), new RuntimeException(FileUtils.readFileToString(tempFile)));
}
finally {
FileUtils.deleteQuietly(tempFile);
}
}
示例6: execute
import org.apache.commons.exec.ExecuteException; //导入依赖的package包/类
/**
* Executes the given command synchronously.
*
* @param command The command to execute.
* @param processInput Input provided to the process.
* @return The result of the execution, or empty if the process does not terminate within the timeout set for this executor.
* @throws IOException if the process execution failed.
*/
public Optional<ProcessResult> execute(String command, String processInput) throws IOException {
ByteArrayOutputStream processErr = new ByteArrayOutputStream();
ByteArrayOutputStream processOut = new ByteArrayOutputStream();
DefaultExecutor executor = new DefaultExecutor();
executor.setStreamHandler(createStreamHandler(processOut, processErr, processInput));
ExecuteWatchdog watchDog = new ExecuteWatchdog(TimeUnit.SECONDS.toMillis(timeoutSeconds));
executor.setWatchdog(watchDog);
executor.setExitValues(successExitCodes);
int exitCode;
try {
exitCode = executor.execute(CommandLine.parse(command));
} catch (ExecuteException e) {
exitCode = e.getExitValue();
}
return (watchDog.killedProcess()) ?
Optional.empty() : Optional.of(new ProcessResult(exitCode, processOut.toString(), processErr.toString()));
}
示例7: stopDc
import org.apache.commons.exec.ExecuteException; //导入依赖的package包/类
protected void stopDc(DcMeta dcMeta) throws ExecuteException, IOException {
for(InetSocketAddress address : IpUtils.parse(dcMeta.getZkServer().getAddress())){
logger.info(remarkableMessage("[stopZkServer]{}"), address);
stopServerListeningPort(address.getPort());
}
for(MetaServerMeta metaServerMeta : dcMeta.getMetaServers()){
logger.info("[stopMetaServer]{}", metaServerMeta);
stopServerListeningPort(metaServerMeta.getPort());
}
for (ClusterMeta clusterMeta : dcMeta.getClusters().values()) {
for (ShardMeta shardMeta : clusterMeta.getShards().values()) {
for (KeeperMeta keeperMeta : shardMeta.getKeepers()) {
logger.info("[stopKeeperServer]{}", keeperMeta.getPort());
stopServerListeningPort(keeperMeta.getPort());
}
for(RedisMeta redisMeta : shardMeta.getRedises()){
logger.info("[stopRedisServer]{}", redisMeta.getPort());
stopServerListeningPort(redisMeta.getPort());
}
}
}
}
示例8: execToString
import org.apache.commons.exec.ExecuteException; //导入依赖的package包/类
private String execToString(File model, File properties) throws ExecuteException, IOException {
String command;
String prism = (System.getProperty("os.name").contains("Windows"))? "prism.bat" : "prism";
if (mConverter.isBoundedNet()) {
command = mPrismPath + " " + model.getAbsolutePath() + " " + properties.getAbsolutePath()
+ " -exportstates " + mFilesPath+mStatesFileName;
} else {
command = mPrismPath + " " + model.getAbsolutePath() + " " + properties.getAbsolutePath() + " -ex";
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ByteArrayOutputStream errorStream = new ByteArrayOutputStream();
CommandLine commandline = CommandLine.parse(command);
DefaultExecutor exec = new DefaultExecutor();
PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream, errorStream);
//Workbench.consoleMessage("Executing: " + command);
exec.setStreamHandler(streamHandler);
System.out.println("Executing "+command);
exec.execute(commandline);
System.out.println("ID-Mapping: "+TransitionToIDMapper.getMapping());
return(outputStream.toString());
}
示例9: asynchExecutionHandler
import org.apache.commons.exec.ExecuteException; //导入依赖的package包/类
private ExecuteResultHandler asynchExecutionHandler()
{
return new ExecuteResultHandler()
{
@Override
public void onProcessFailed(ExecuteException ex)
{
throw new RuntimeException("Engine operation failed.", ex);
}
@Override
public void onProcessComplete(int exitValue)
{
context.log.info("Engine process stopped.");
}
};
}
示例10: waitForExit
import org.apache.commons.exec.ExecuteException; //导入依赖的package包/类
public void waitForExit(CppcheckProcessResultHandler resultHandler,
IProgressMonitor monitor) throws InterruptedException,
ProcessExecutionException, IOException {
try {
while (resultHandler.isRunning()) {
Thread.sleep(SLEEP_TIME_MS);
if (monitor.isCanceled()) {
watchdog.destroyProcess();
throw new InterruptedException("Process killed");
}
}
// called to throw execution in case of invalid exit code
resultHandler.getExitValue();
} catch (ExecuteException e) {
// we need to rethrow the error to include the command line
// since the error dialog does not display nested exceptions,
// include original error string
throw ProcessExecutionException.newException(cmdLine.toString(), e);
} finally {
processStdErr.close();
processStdOut.close();
}
long endTime = System.currentTimeMillis();
console.println("Duration " + String.valueOf(endTime - startTime)
+ " ms.");
}
示例11: onTranscodeProcessFailed
import org.apache.commons.exec.ExecuteException; //导入依赖的package包/类
@Override
public void onTranscodeProcessFailed(ExecuteException e, ExecuteWatchdog watchdog, long timestamp) {
// TODO Auto-generated method stub
String cause = null;
if(watchdog != null && watchdog.killedProcess()) cause = FAILURE_BY_TIMEOUT;
else cause = GENERIC_FAILURE;
if(timestamp - this.resultHandler.getAbortRequestTimestamp()>ABORT_TIMEOUT)
{
logger.warn("onTranscodeProcessFailed cause: " + cause);
notifyObservers(SessionEvent.FAILED, new TranscoderExecutionError(e, cause, timestamp));
}
else
{
logger.warn("Probable force abort");
doCleanUp();
}
}
示例12: runOnLocalhost
import org.apache.commons.exec.ExecuteException; //导入依赖的package包/类
public static ExecuteResult runOnLocalhost(ExecExceptionHandling exceptionHandling, CommandLine cmdLineOnLocalhost)
throws ExecuteException, IOException {
DefaultExecutor executor = new DefaultExecutor();
OutputsToStringStreamHandler streamHandler = new OutputsToStringStreamHandler();
executor.setStreamHandler(streamHandler);
executor.setExitValues(null);
int exitValue = executor.execute(cmdLineOnLocalhost);
ExecuteResult result = new ExecuteResult(streamHandler.getStandardOutput(), streamHandler.getStandardError(),
exitValue);
switch (exceptionHandling) {
case RETURN_EXIT_CODE_WITHOUT_THROWING_EXCEPTION:
break;
case THROW_EXCEPTION_IF_EXIT_CODE_NOT_0:
if (exitValue != 0) {
throw new ExecuteException("Failed to execute " + cmdLineOnLocalhost + " - Output: " + result,
exitValue);
}
break;
default:
break;
}
return result;
}
示例13: testDeleteAndCopyFileHdfs
import org.apache.commons.exec.ExecuteException; //导入依赖的package包/类
@Test
public void testDeleteAndCopyFileHdfs() throws ExecuteException, IOException {
resetTransferDirectories(SMALL_NUMBER_OF_FILES);
String testFilename = getTestFilename(0);
File hdfsFile = new File("/tmp/copy-file-test", testFilename);
ShmackUtils.deleteInHdfs(hdfsFile);
assertHdfsFileOrFolderDoesNotExist(hdfsFile);
File localSrcFile = new File(LOCAL_SRC_DIR, testFilename);
ShmackUtils.copyToHdfs(localSrcFile, hdfsFile);
File localTargetFile = new File(LOCAL_TARGET_DIR, testFilename);
ShmackUtils.copyFromHdfs(hdfsFile, localTargetFile);
assertFileContentEquals(LOCAL_SRC_DIR, LOCAL_TARGET_DIR, testFilename);
ShmackUtils.deleteInHdfs(hdfsFile);
assertHdfsFileOrFolderDoesNotExist(hdfsFile);
}
示例14: run
import org.apache.commons.exec.ExecuteException; //导入依赖的package包/类
public static int run(final GeneratorConfig gc, final ExecutionConfig ec) throws IOException, InterruptedException {
final File configFile = File.createTempFile("trainbenchmark-generator-", ".conf");
final String configPath = configFile.getAbsolutePath();
gc.saveToFile(configPath);
final String projectName = String.format("trainbenchmark-generator-%s", gc.getProjectName());
final String jarPath = String.format("../%s/build/libs/%s-1.0.0-SNAPSHOT-fat.jar", projectName, projectName);
final String javaCommand = String.format("java -Xms%s -Xmx%s -server -jar %s %s", ec.getXms(), ec.getXmx(),
jarPath, configPath);
final CommandLine cmdLine = CommandLine.parse(javaCommand);
final DefaultExecutor executor = new DefaultExecutor();
try {
final int exitValue = executor.execute(cmdLine);
System.out.println();
return exitValue;
} catch (final ExecuteException e) {
e.printStackTrace(System.out);
return e.getExitValue();
}
}
示例15: onProcessFailedShouldWrapCause
import org.apache.commons.exec.ExecuteException; //导入依赖的package包/类
@Test
public void onProcessFailedShouldWrapCause() throws Exception {
// Arrange
ProcessHandler mockProcessHandler = mock(ProcessHandler.class);
ForwardingExecuteResultHandler target = new ForwardingExecuteResultHandler(mockProcessHandler);
ExecuteException expectedCause = new ExecuteException("foo", -123);
// Act
target.onProcessFailed(expectedCause);
// Assert
ArgumentCaptor<ProcessException> captor = captorForClass(ProcessException.class);
verify(mockProcessHandler).onProcessFailed(captor.capture());
Throwable cause = captor.getValue().getCause();
assertThat(cause).isEqualTo(expectedCause);
}