本文整理汇总了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;
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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()));
}
示例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();
}
}
示例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();
}
示例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*/
}
}
示例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);
}
示例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();
}
}