Search in sources :

Example 1 with CloseableProcess

use of fish.payara.arquillian.container.payara.process.CloseableProcess in project Payara by payara.

the class PayaraServerControl method executeAdminCommand.

private void executeAdminCommand(String description, String command, List<String> args, ProcessOutputConsumer consumer) throws LifecycleException {
    final List<String> cmd = buildCommand(command, args);
    if (config.isOutputToConsole()) {
        System.out.println(description + " using command: " + cmd.toString());
    }
    int result;
    try (CloseableProcess process = new CloseableProcess(new ProcessBuilder(cmd).redirectErrorStream(true).start());
        ConsoleReader consoleReader = new ConsoleReader(process, consumer)) {
        new Thread(consoleReader).start();
        result = process.waitFor();
    } catch (IOException | InterruptedException e) {
        logger.log(SEVERE, description + (e instanceof IOException ? " failed." : " interrupted."), e);
        throw new LifecycleException("Unable to execute " + cmd.toString(), e);
    }
    if (result != 0) {
        throw new LifecycleException("Unable to execute " + cmd.toString());
    }
}
Also used : LifecycleException(org.jboss.arquillian.container.spi.client.container.LifecycleException) ConsoleReader(fish.payara.arquillian.container.payara.process.ConsoleReader) CloseableProcess(fish.payara.arquillian.container.payara.process.CloseableProcess) IOException(java.io.IOException)

Aggregations

CloseableProcess (fish.payara.arquillian.container.payara.process.CloseableProcess)1 ConsoleReader (fish.payara.arquillian.container.payara.process.ConsoleReader)1 IOException (java.io.IOException)1 LifecycleException (org.jboss.arquillian.container.spi.client.container.LifecycleException)1