use of org.apache.commons.exec.Executor in project project-build-plugin by axonivy.
the class TestStartEngine method testKillEngineOnVmExit.
@Test
public void testKillEngineOnVmExit() throws Exception {
StartTestEngineMojo mojo = rule.getMojo();
Executor startedProcess = null;
try {
startedProcess = mojo.startEngine();
assertThat(startedProcess.getProcessDestroyer()).isInstanceOf(ShutdownHookProcessDestroyer.class);
ShutdownHookProcessDestroyer jvmShutdownHoock = (ShutdownHookProcessDestroyer) startedProcess.getProcessDestroyer();
assertThat(jvmShutdownHoock.size()).as("One started engine process must be killed on VM end.").isEqualTo(1);
} finally {
kill(startedProcess);
}
}
use of org.apache.commons.exec.Executor in project project-build-plugin by axonivy.
the class TestStartEngine method canStartEngine.
@Test
public void canStartEngine() throws Exception {
StartTestEngineMojo mojo = rule.getMojo();
assertThat(getProperty(EngineControl.Property.TEST_ENGINE_URL)).isNull();
assertThat(getProperty(EngineControl.Property.TEST_ENGINE_LOG)).isNull();
Executor startedProcess = null;
try {
startedProcess = mojo.startEngine();
assertThat(getProperty(EngineControl.Property.TEST_ENGINE_URL)).startsWith("http://");
assertThat(new File(getProperty(EngineControl.Property.TEST_ENGINE_LOG))).exists();
} finally {
kill(startedProcess);
}
}
use of org.apache.commons.exec.Executor 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.Executor in project smarthome by eclipse.
the class ExecUtil method executeCommandLineAndWaitResponse.
/**
* <p>
* Executes <code>commandLine</code>. Sometimes (especially observed on MacOS) the commandLine isn't executed
* properly. In that cases another exec-method is to be used. To accomplish this please use the special delimiter '
* <code>@@</code>'. If <code>commandLine</code> contains this delimiter it is split into a String[] array and the
* special exec-method is used.
*
* <p>
* A possible {@link IOException} gets logged but no further processing is done.
*
* @param commandLine the command line to execute
* @param timeout timeout for execution in milliseconds
* @return response data from executed command line
*/
public static String executeCommandLineAndWaitResponse(String commandLine, int timeout) {
String retval = null;
CommandLine cmdLine = null;
if (commandLine.contains(CMD_LINE_DELIMITER)) {
String[] cmdArray = commandLine.split(CMD_LINE_DELIMITER);
cmdLine = new CommandLine(cmdArray[0]);
for (int i = 1; i < cmdArray.length; i++) {
cmdLine.addArgument(cmdArray[i], false);
}
} else {
cmdLine = CommandLine.parse(commandLine);
}
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout);
Executor executor = new DefaultExecutor();
ByteArrayOutputStream stdout = new ByteArrayOutputStream();
PumpStreamHandler streamHandler = new PumpStreamHandler(stdout);
executor.setExitValues(null);
executor.setStreamHandler(streamHandler);
executor.setWatchdog(watchdog);
Logger logger = LoggerFactory.getLogger(ExecUtil.class);
try {
executor.execute(cmdLine, resultHandler);
logger.debug("executed commandLine '{}'", commandLine);
} catch (ExecuteException e) {
logger.warn("couldn't execute commandLine '{}'", commandLine, e);
} catch (IOException e) {
logger.warn("couldn't execute commandLine '{}'", commandLine, e);
}
// can safely request the exit code
try {
resultHandler.waitFor();
int exitCode = resultHandler.getExitValue();
retval = StringUtils.chomp(stdout.toString());
if (resultHandler.getException() != null) {
logger.warn("{}", resultHandler.getException().getMessage());
} else {
logger.debug("exit code '{}', result '{}'", exitCode, retval);
}
} catch (InterruptedException e) {
logger.warn("Timeout occurred when executing commandLine '{}'", commandLine, e);
}
return retval;
}
use of org.apache.commons.exec.Executor in project stanbol by apache.
the class JarExecutor method start.
/**
* Start the jar if not done yet, and setup runtime hook to stop it.
*/
public void start() throws Exception {
final ExecuteResultHandler h = new ExecuteResultHandler() {
@Override
public void onProcessFailed(ExecuteException ex) {
log.error("Process execution failed:" + ex, ex);
}
@Override
public void onProcessComplete(int result) {
log.info("Process execution complete, exit code=" + result);
}
};
final String vmOptions = System.getProperty("jar.executor.vm.options");
final Executor e = new DefaultExecutor();
if (this.workingDirectory != null) {
e.setWorkingDirectory(this.workingDirectory);
}
final CommandLine cl = new CommandLine(javaExecutable);
if (vmOptions != null && vmOptions.length() > 0) {
// not the case for common usage patterns
for (String option : StringUtils.split(vmOptions, " ")) {
cl.addArgument(option);
}
}
cl.addArgument("-jar");
cl.addArgument(jarToExecute.getAbsolutePath());
cl.addArgument("-p");
cl.addArgument(String.valueOf(serverPort));
log.info("Executing " + cl);
e.setStreamHandler(new PumpStreamHandler());
e.setProcessDestroyer(new ShutdownHookProcessDestroyer());
e.execute(cl, h);
}
Aggregations