當前位置: 首頁>>代碼示例>>Java>>正文


Java ExecuteException類代碼示例

本文整理匯總了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;
}
 
開發者ID:polygOnetic,項目名稱:guetzliconverter,代碼行數:19,代碼來源:ProcessExecutor.java

示例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;
}
 
開發者ID:coala,項目名稱:coala-eclipse,代碼行數:22,代碼來源:ExternalUtils.java

示例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);
  }
}
 
開發者ID:creactiviti,項目名稱:piper,代碼行數:20,代碼來源:Mediainfo.java

示例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);
  }
}
 
開發者ID:creactiviti,項目名稱:piper,代碼行數:21,代碼來源:Ffmpeg.java

示例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);
  }
}
 
開發者ID:creactiviti,項目名稱:piper,代碼行數:27,代碼來源:Ffprobe.java

示例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()));
}
 
開發者ID:vespa-engine,項目名稱:vespa,代碼行數:28,代碼來源:ProcessExecutor.java

示例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());
			}
		}
	}
}
 
開發者ID:ctripcorp,項目名稱:x-pipe,代碼行數:26,代碼來源:AbstractFullIntegrated.java

示例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());
    
}
 
開發者ID:iig-uni-freiburg,項目名稱:SWAT20,代碼行數:25,代碼來源:PRISM.java

示例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.");
      }
    };
}
 
開發者ID:axonivy,項目名稱:project-build-plugin,代碼行數:18,代碼來源:EngineControl.java

示例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.");
}
 
開發者ID:kwin,項目名稱:cppcheclipse,代碼行數:27,代碼來源:AbstractCppcheckCommand.java

示例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();
	}
}
 
開發者ID:rajdeeprath,項目名稱:poor-man-transcoder,代碼行數:20,代碼來源:Session.java

示例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;
}
 
開發者ID:Zuehlke,項目名稱:SHMACK,代碼行數:24,代碼來源:ShmackUtils.java

示例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);
}
 
開發者ID:Zuehlke,項目名稱:SHMACK,代碼行數:22,代碼來源:ShmackUtilsTest.java

示例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();
	}
}
 
開發者ID:FTSRG,項目名稱:trainbenchmark,代碼行數:22,代碼來源:GeneratorRunner.java

示例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);
}
 
開發者ID:SEEG-Oxford,項目名稱:ABRAID-MP,代碼行數:17,代碼來源:ForwardingExecuteResultHandlerTest.java


注:本文中的org.apache.commons.exec.ExecuteException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。