use of org.apache.commons.exec.ExecuteWatchdog in project evosuite by EvoSuite.
the class ProcessLauncher method launchNewProcess.
public int launchNewProcess(File baseDir, String cmdString, int timeout) throws IOException, ProcessTimeoutException {
DefaultExecutor executor = new DefaultExecutor();
ExecuteWatchdog timeoutWatchdog = new ExecuteWatchdog(timeout);
executor.setWatchdog(timeoutWatchdog);
PumpStreamHandler streamHandler = new PumpStreamHandler(this.outAndErr, this.outAndErr, this.input);
executor.setStreamHandler(streamHandler);
if (baseDir != null) {
executor.setWorkingDirectory(baseDir);
}
int exitValue;
try {
logger.debug("About to execute command " + cmdString);
exitValue = executor.execute(CommandLine.parse(cmdString));
if (executor.isFailure(exitValue) && timeoutWatchdog.killedProcess()) {
// it was killed on purpose by the watchdog
logger.debug("A timeout occured while executing a process");
logger.debug("The command is " + cmdString);
throw new ProcessTimeoutException("A timeout occurred while executing command " + cmdString);
}
return exitValue;
} catch (ExecuteException e) {
if (timeoutWatchdog.killedProcess()) {
logger.debug("A timeout occured while executing a process");
logger.debug("The command is " + cmdString);
throw new ProcessTimeoutException("A timeout occurred while executing command " + cmdString);
} else {
throw e;
}
}
}
use of org.apache.commons.exec.ExecuteWatchdog in project mule by mulesoft.
the class AbstractOSController method executeSyncCommand.
private int executeSyncCommand(String command, String[] args, Map<Object, Object> newEnv, int timeout) throws MuleControllerException {
CommandLine commandLine = new CommandLine(muleBin);
commandLine.addArgument(command);
commandLine.addArguments(args);
DefaultExecutor executor = new DefaultExecutor();
ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout);
executor.setWatchdog(watchdog);
executor.setStreamHandler(new PumpStreamHandler());
return doExecution(executor, commandLine, newEnv);
}
use of org.apache.commons.exec.ExecuteWatchdog in project mule by mulesoft.
the class MuleUtils method executeCommand.
public static int executeCommand(String command, String... envVars) throws IOException {
CommandLine cmdLine = CommandLine.parse(command);
DefaultExecutor executor = new DefaultExecutor();
Map<String, String> env = addEnvProperties(envVars);
ExecuteWatchdog watchDog = new ExecuteWatchdog(TIMEOUT);
executor.setWatchdog(watchDog);
executor.setStreamHandler(new PumpStreamHandler());
int result = executor.execute(cmdLine, env);
if (executor.isFailure(result)) {
if (watchDog.killedProcess()) {
throw new RuntimeException("Reached timeout while running: " + cmdLine);
}
throw new RuntimeException("Process failed with return code [" + result + "]: " + cmdLine);
}
return result;
}
use of org.apache.commons.exec.ExecuteWatchdog in project fmv by f-agu.
the class FMVExecutor method setTimeOut.
/**
* @param timeOutMilliSeconds
*/
public void setTimeOut(long timeOutMilliSeconds) {
if (timeOutMilliSeconds >= 0 && timeOutMilliSeconds < 10) {
throw new IllegalArgumentException("Incredible timeout: " + timeOutMilliSeconds + "ms");
}
this.timeOutMilliSeconds = Math.max(timeOutMilliSeconds, org.apache.commons.exec.ExecuteWatchdog.INFINITE_TIMEOUT);
executeWatchdog = new ExecuteWatchdog(timeOutMilliSeconds);
setWatchdog(executeWatchdog);
}
use of org.apache.commons.exec.ExecuteWatchdog in project zeppelin by apache.
the class MongoDbInterpreter method stopProcess.
private void stopProcess(String paragraphId) {
if (runningProcesses.containsKey(paragraphId)) {
final Executor executor = runningProcesses.get(paragraphId);
final ExecuteWatchdog watchdog = executor.getWatchdog();
watchdog.destroyProcess();
runningProcesses.remove(paragraphId);
}
}
Aggregations