Search in sources :

Example 1 with StreamRedirector

use of org.openntf.openliberty.domino.util.StreamRedirector in project openliberty-domino by OpenNTF.

the class LibertyServerInstance method sendCommand.

private Process sendCommand(Path path, Path javaHome, String command, Object... args) {
    try {
        // $NON-NLS-1$
        Path serverScript = path.resolve("bin").resolve(serverFile);
        List<String> commands = new ArrayList<>();
        commands.add(serverScript.toString());
        commands.add(command);
        for (Object arg : args) {
            commands.add(StringUtil.toString(arg));
        }
        ProcessBuilder pb = new ProcessBuilder().command(commands);
        Map<String, String> env = pb.environment();
        // $NON-NLS-1$
        env.put("JAVA_HOME", javaHome.toString());
        // $NON-NLS-1$
        String sysPath = System.getenv("PATH");
        sysPath += File.pathSeparator + dominoProgramDirectory;
        // $NON-NLS-1$
        env.put("PATH", sysPath);
        // $NON-NLS-1$
        env.put("Domino_HTTP", getServerBase());
        if (log.isLoggable(Level.FINE)) {
            // $NON-NLS-1$
            OpenLibertyLog.getLog().fine(format(Messages.getString("OpenLibertyRuntime.executingCommand"), pb.command()));
        }
        Process process = pb.start();
        subprocesses.add(process);
        DominoThreadFactory.getExecutor().submit(new StreamRedirector(process.getInputStream()));
        DominoThreadFactory.getExecutor().submit(new StreamRedirector(process.getErrorStream()));
        return process;
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : Path(java.nio.file.Path) StreamRedirector(org.openntf.openliberty.domino.util.StreamRedirector) ArrayList(java.util.ArrayList) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Aggregations

IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 StreamRedirector (org.openntf.openliberty.domino.util.StreamRedirector)1