当前位置: 首页>>代码示例>>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;未经允许,请勿转载。