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


Java ExecuteException.getExitValue方法代碼示例

本文整理匯總了Java中org.apache.commons.exec.ExecuteException.getExitValue方法的典型用法代碼示例。如果您正苦於以下問題:Java ExecuteException.getExitValue方法的具體用法?Java ExecuteException.getExitValue怎麽用?Java ExecuteException.getExitValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.exec.ExecuteException的用法示例。


在下文中一共展示了ExecuteException.getExitValue方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: onProcessFailed

import org.apache.commons.exec.ExecuteException; //導入方法依賴的package包/類
@Override
public void onProcessFailed(ExecuteException executeException) {
    executor.exception = Optional.of(executeException);
    executor.exitValue = executeException.getExitValue();
    CmdResultHandler.this.onProcessComplete(executeException.getExitValue(), executor.exception, getOutputStream(), getErrorStream());
    countDown();
}
 
開發者ID:raftelti,項目名稱:adb4j,代碼行數:8,代碼來源:CmdResultHandler.java

示例8: executeGatling

import org.apache.commons.exec.ExecuteException; //導入方法依賴的package包/類
private void executeGatling(List<String> gatlingJvmArgs, List<String> gatlingArgs, List<String> testClasspath, Toolchain toolchain) throws Exception {
  Fork forkedGatling = new Fork(GATLING_MAIN_CLASS, testClasspath, gatlingJvmArgs, gatlingArgs, toolchain, propagateSystemProperties, getLog());
  try {
    forkedGatling.run();
  } catch (ExecuteException e) {
    if (e.getExitValue() == 2)
      throw new GatlingSimulationAssertionsFailedException(e);
    else
      throw e; /* issue 1482*/
  }
}
 
開發者ID:gatling,項目名稱:gatling-maven-plugin,代碼行數:12,代碼來源:GatlingMojo.java

示例9: run

import org.apache.commons.exec.ExecuteException; //導入方法依賴的package包/類
/**
 * Run a command against the local operating system.
 *
 * @param cmd wraps the api of org.apache.commons.exec.CommandLine to create and run rich commands.
 * @return Output - encapsulates exit code, stdOut and stdErr from a run command.
 * @throws IOException
 */
public static Std run(Cmd cmd) throws IOException {

    DefaultExecutor exec = new DefaultExecutor();
    ByteArrayOutputStream stdOut = new ByteArrayOutputStream();
    ByteArrayOutputStream stdErr = new ByteArrayOutputStream();
    exec.setStreamHandler(new PumpStreamHandler(stdOut, stdErr));
    int exitCode;
    try {
        exitCode = exec.execute(cmd.getCommandLine());
    } catch (ExecuteException e) {
        exitCode = e.getExitValue();
    }
    return new Std(exitCode, stdOut, stdErr);
}
 
開發者ID:imaginatelabs,項目名稱:shellbert,代碼行數:22,代碼來源:Sh.java

示例10: runPerformanceBenchmark

import org.apache.commons.exec.ExecuteException; //導入方法依賴的package包/類
public static int runPerformanceBenchmark(final BenchmarkConfig bc, final ExecutionConfig ec)
		throws IOException, InterruptedException {
	final Joiner joiner = Joiner.on(", ");
	System.out.println("Running benchmark.");
	System.out.println("Workload: " + bc.getConfigBase().getWorkload());
	System.out.println("Tool: " + bc.getToolName());
	System.out.println("Model: " + bc.getConfigBase().getModelPath());
	System.out.println("Description: " + bc.getDescription());
	System.out.println("Operations: [" + joiner.join(bc.getConfigBase().getOperations()) + "]");
	System.out.println("Execution configuration: " + ec);
	System.out.println("Runs: " + bc.getConfigBase().getRuns());

	final File configFile = File.createTempFile("trainbenchmark-benchmark-", ".conf");
	final String configPath = configFile.getAbsolutePath();
	bc.saveToFile(configPath);

	final String projectName = String.format("trainbenchmark-tool-%s", bc.getProjectName());
	final String jarPath = String.format("../%s/build/libs/%s-1.0.0-SNAPSHOT-fat.jar %s", projectName, projectName,
			configPath);

	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 long timeoutInSeconds = bc.getConfigBase().getTimeout();
	final long timeoutInMilliseconds = timeoutInSeconds * 1000;
	final ExecuteWatchdog watchdog = new ExecuteWatchdog(timeoutInMilliseconds);
	final Executor executor = new DefaultExecutor();
	executor.setWatchdog(watchdog);
	executor.setStreamHandler(new PumpStreamHandler());
	try {
		final int exitValue = executor.execute(cmdLine);
		System.out.println();
		return exitValue;
	} catch (final ExecuteException e) {
		if (watchdog.killedProcess()) {
			System.out.println("Process timed out.");
		} else {
			e.printStackTrace(System.out);
		}
		return e.getExitValue();
	}
}
 
開發者ID:FTSRG,項目名稱:trainbenchmark,代碼行數:44,代碼來源:BenchmarkRunner.java


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