    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 *  contributor license agreements.  See the NOTICE file distributed with
    004 *  this work for additional information regarding copyright ownership.
    005 *  The ASF licenses this file to You under the Apache License, Version 2.0
    006 *  (the "License"); you may not use this file except in compliance with
    007 *  the License.  You may obtain a copy of the License at
    008 *
    009 *      http://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 *  Unless required by applicable law or agreed to in writing, software
    012 *  distributed under the License is distributed on an "AS IS" BASIS,
    013 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 *  See the License for the specific language governing permissions and
    015 *  limitations under the License.
    016 */
    017
    018package org.apache.commons.exec.launcher;
    019
    020import java.io.File;
    021import java.io.IOException;
    022import java.util.Map;
    023
    024import org.apache.commons.exec.CommandLine;
    025
    026/**
    027 * Abstracts platform-dependent implementations.
    028 */
    029public interface CommandLauncher {
    030
    031    /**
    032     * Executes the given command in a new process.
    033     *
    034     * @param commandLine The command to execute.
    035     * @param env         The environment for the new process. If null, the environment of the current process is used.
    036     * @return the newly created process.
    037     * @throws IOException if attempting to run a command in a specific directory.
    038     */
    039    Process exec(final CommandLine commandLine, final Map<String, String> env) throws IOException;
    040
    041    /**
    042     * Executes the given command in a new process, in the given working directory.
    043     *
    044     * @param commandLine      The command to execute.
    045     * @param env              The environment for the new process. If null, the environment of the current process is used.
    046     * @param workingDirectory The directory to start the command in. If null, the current directory is used.
    047     * @return the newly created process.
    048     * @throws IOException if trying to change directory.
    049     */
    050    Process exec(final CommandLine commandLine, final Map<String, String> env, final File workingDirectory) throws IOException;
    051
    052    /**
    053     * Tests whether {@code exitValue} signals a failure on the current system (OS specific).
    054     * <p>
    055     * <b>Note</b> that this method relies on the conventions of the OS, it will return false results if the application you are running doesn't follow these
    056     * conventions. One notable exception is the Java VM provided by HP for OpenVMS - it will return 0 if successful (like on any other platform), but this
    057     * signals a failure on OpenVMS. So if you execute a new Java VM on OpenVMS, you cannot trust this method.
    058     * </p>
    059     *
    060     * @param exitValue the exit value (return code) to be checked.
    061     * @return {@code true} if {@code exitValue} signals a failure.
    062     */
    063    boolean isFailure(final int exitValue);
    064}