Example usage for java.lang ProcessImpl ProcessImpl

List of usage examples for java.lang ProcessImpl ProcessImpl

Introduction

In this page you can find the example usage for java.lang ProcessImpl ProcessImpl.

Prototype

ProcessImpl

Source Link

Usage

From source file:edu.umn.msi.tropix.common.execution.process.impl.ProcessFactoryImpl.java

public Process createProcess(final ProcessConfiguration processConfiguration) {
    final List<String> command = new LinkedList<String>();
    final String application = processConfiguration.getApplication();
    Preconditions.checkNotNull(application, "Attempted to create process with null application.");
    command.add(application);//from   w  w  w . j  a va 2s  .c o m
    final List<String> arguments = processConfiguration.getArguments();
    if (arguments != null) {
        command.addAll(processConfiguration.getArguments());
    }
    LOG.trace("Creating process builder with commands " + Joiner.on(" ").join(command) + " in directory "
            + processConfiguration.getDirectory());
    final ProcessBuilder processBuilder = new ProcessBuilder(command);
    if (processConfiguration.getEnvironment() != null) {
        for (final Entry<String, String> entry : processConfiguration.getEnvironment().entrySet()) {
            processBuilder.environment().put(entry.getKey(), entry.getValue());
        }
    }
    processBuilder.directory(processConfiguration.getDirectory());

    java.lang.Process baseProcess = null;
    try {
        baseProcess = processBuilder.start();
    } catch (final IOException e) {
        throw new IllegalStateException(
                "Failed to start process corresponding to process configuration " + processConfiguration, e);
    }
    final ProcessImpl process = new ProcessImpl();
    process.setBaseProcess(baseProcess);
    return process;
}