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     */
018    
019    package org.apache.commons.exec.launcher;
020    
021    import java.io.File;
022    import java.io.IOException;
023    import java.util.Map;
024    
025    import org.apache.commons.exec.CommandLine;
026    
027    /**
028     * Interface to shield the caller from the various platform-dependent
029     * implementations.
030     */
031    public interface CommandLauncher {
032    
033        /**
034         * Launches the given command in a new process.
035         * 
036         * @param cmd
037         *            The command to execute
038         * @param env
039         *            The environment for the new process. If null, the environment
040         *            of the current process is used.
041         * 
042         * @return the newly created process
043         * @throws IOException
044         *             if attempting to run a command in a specific directory
045         */
046        Process exec(final CommandLine cmd, final Map env)
047                throws IOException;
048    
049        /**
050         * Launches the given command in a new process, in the given working
051         * directory.
052         * 
053         * @param cmd
054         *            The command to execute
055         * @param env
056         *            The environment for the new process. If null, the environment
057         *            of the current process is used.
058         * @param workingDir
059         *            The directory to start the command in. If null, the current
060         *            directory is used
061         *
062         * @return the newly created process
063         * @throws IOException
064         *             if trying to change directory
065         */
066        Process exec(final CommandLine cmd, final Map env,
067                final File workingDir) throws IOException;
068    
069    
070        /**
071         * Checks whether <code>exitValue</code> signals a failure on the current
072         * system (OS specific).
073         * <p>
074         * <b>Note</b> that this method relies on the conventions of the OS, it
075         * will return false results if the application you are running doesn't
076         * follow these conventions. One notable exception is the Java VM provided
077         * by HP for OpenVMS - it will return 0 if successful (like on any other
078         * platform), but this signals a failure on OpenVMS. So if you execute a new
079         * Java VM on OpenVMS, you cannot trust this method.
080         * </p>
081         *
082         * @param exitValue the exit value (return code) to be checked
083         * @return <code>true</code> if <code>exitValue</code> signals a failure
084         */
085        boolean isFailure(final int exitValue);
086    }