use of org.apache.commons.exec.ExecuteWatchdog in project alliance by codice.
the class MpegTsUdpClient method executeFFmpeg.
private static DefaultExecuteResultHandler executeFFmpeg(final CommandLine command, final int timeoutSeconds, final PumpStreamHandler streamHandler) throws IOException {
final ExecuteWatchdog watchdog = new ExecuteWatchdog(timeoutSeconds * 1000);
final Executor executor = new DefaultExecutor();
executor.setWatchdog(watchdog);
if (streamHandler != null) {
executor.setStreamHandler(streamHandler);
}
final DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
executor.execute(command, resultHandler);
return resultHandler;
}
use of org.apache.commons.exec.ExecuteWatchdog in project oxCore by GluuFederation.
the class ProcessHelper method executeProgram.
/**
* @param printJobTimeout
* the printJobTimeout (ms) before the watchdog terminates the print
* process
* @param printInBackground
* printing done in the background or blocking
* @param streamHandler
* @return a print result handler (implementing a future)
* @throws IOException
* the test failed
*/
public static PrintResultHandler executeProgram(CommandLine commandLine, String workingDirectory, long printJobTimeout, boolean printInBackground, int successExitValue, ExecuteStreamHandler streamHandler) throws IOException {
ExecuteWatchdog watchdog = null;
PrintResultHandler resultHandler;
// Create the executor and consider the successExitValue as success
Executor executor = new DefaultExecutor();
executor.setExitValue(successExitValue);
if (StringHelper.isNotEmpty(workingDirectory)) {
executor.setWorkingDirectory(new File(workingDirectory));
}
// Redirect streams if needed
if (streamHandler != null) {
executor.setStreamHandler(streamHandler);
}
// Create a watchdog if requested
if (printJobTimeout > 0) {
watchdog = new ExecuteWatchdog(printJobTimeout);
executor.setWatchdog(watchdog);
}
// Pass a "ExecuteResultHandler" when doing background printing
if (printInBackground) {
LOG.debug(String.format("Executing non-blocking process %s", commandLine.toString()));
resultHandler = new PrintResultHandler(watchdog);
executor.execute(commandLine, resultHandler);
} else {
LOG.debug(String.format("Executing blocking process %s", commandLine.toString()));
successExitValue = executor.execute(commandLine);
resultHandler = new PrintResultHandler(successExitValue);
}
return resultHandler;
}
use of org.apache.commons.exec.ExecuteWatchdog in project Saturn by vipshop.
the class ScriptPidUtils method exeCmdWithoutPipe.
public static String exeCmdWithoutPipe(CommandLine cmdLine, ByteArrayInputStream input, Map<String, String> env) {
DefaultExecutor executor = new DefaultExecutor();
ExecuteWatchdog dog = new ExecuteWatchdog(3 * 1000);
executor.setWatchdog(dog);
executor.setExitValue(0);
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
SaturnLogOutputStream errorOS = new SaturnLogOutputStream(log, SaturnLogOutputStream.LEVEL_ERROR);
PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream, errorOS, input);
executor.setStreamHandler(streamHandler);
LogUtils.info(log, LogEvents.ExecutorEvent.COMMON, "exec command: {}", cmdLine);
int value = executor.execute(cmdLine, env);
if (value == 0) {
String out = outputStream.toString();
return out;
} else {
return null;
}
} catch (Exception e) {
LogUtils.error(log, LogEvents.ExecutorEvent.COMMON, e.getMessage(), e);
return null;
}
}
use of org.apache.commons.exec.ExecuteWatchdog in project project-build-plugin by axonivy.
the class EngineControl method start.
public Executor start() throws Exception {
CommandLine startCmd = toEngineCommand(Command.start);
context.log.info("Start Axon Ivy Engine in folder: " + context.engineDirectory);
Executor executor = createEngineExecutor();
executor.setStreamHandler(createEngineLogStreamForwarder(logLine -> findStartEngineUrl(logLine)));
executor.setWatchdog(new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT));
executor.setProcessDestroyer(new ShutdownHookProcessDestroyer());
executor.execute(startCmd, asynchExecutionHandler());
waitForEngineStart(executor);
return executor;
}
use of org.apache.commons.exec.ExecuteWatchdog in project tycho by eclipse.
the class DefaultEquinoxLauncher method execute.
@Override
public int execute(LaunchConfiguration configuration, int forkedProcessTimeoutInSeconds) throws EquinoxLaunchingException {
String executable = configuration.getJvmExecutable();
if (executable == null || "".equals(executable)) {
// use the same JVM as the one used to run Maven (the "java.home" one)
executable = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java";
if (File.separatorChar == '\\') {
executable = executable + ".exe";
}
}
CommandLine cli = new CommandLine(executable);
final boolean handleQuotes = false;
cli.addArguments(configuration.getVMArguments(), handleQuotes);
cli.addArguments(new String[] { "-jar", getCanonicalPath(configuration.getLauncherJar()) }, handleQuotes);
cli.addArguments(configuration.getProgramArguments(), handleQuotes);
log.info("Command line:\n\t" + cli.toString());
DefaultExecutor executor = new DefaultExecutor();
ExecuteWatchdog watchdog = null;
if (forkedProcessTimeoutInSeconds > 0) {
watchdog = new ExecuteWatchdog(forkedProcessTimeoutInSeconds * 1000L);
executor.setWatchdog(watchdog);
}
// best effort to avoid orphaned child process
executor.setProcessDestroyer(new ShutdownHookProcessDestroyer());
executor.setWorkingDirectory(configuration.getWorkingDirectory());
try {
return executor.execute(cli, getMergedEnvironment(configuration));
} catch (ExecuteException e) {
if (watchdog != null && watchdog.killedProcess()) {
log.error("Timeout " + forkedProcessTimeoutInSeconds + " s exceeded. Process was killed.");
}
return e.getExitValue();
} catch (IOException e) {
throw new EquinoxLaunchingException(e);
}
}
Aggregations