View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    *  contributor license agreements.  See the NOTICE file distributed with
4    *  this work for additional information regarding copyright ownership.
5    *  The ASF licenses this file to You under the Apache License, Version 2.0
6    *  (the "License"); you may not use this file except in compliance with
7    *  the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   *  Unless required by applicable law or agreed to in writing, software
12   *  distributed under the License is distributed on an "AS IS" BASIS,
13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   *  See the License for the specific language governing permissions and
15   *  limitations under the License.
16   */
17  
18  package org.apache.commons.exec.launcher;
19  
20  import java.io.File;
21  import java.io.IOException;
22  import java.util.Map;
23  
24  import org.apache.commons.exec.CommandLine;
25  
26  /**
27   * Abstracts platform-dependent implementations.
28   */
29  public interface CommandLauncher {
30  
31      /**
32       * Executes the given command in a new process.
33       *
34       * @param commandLine The command to execute.
35       * @param env         The environment for the new process. If null, the environment of the current process is used.
36       * @return the newly created process.
37       * @throws IOException if attempting to run a command in a specific directory.
38       */
39      Process exec(final CommandLine commandLine, final Map<String, String> env) throws IOException;
40  
41      /**
42       * Executes the given command in a new process, in the given working directory.
43       *
44       * @param commandLine      The command to execute.
45       * @param env              The environment for the new process. If null, the environment of the current process is used.
46       * @param workingDirectory The directory to start the command in. If null, the current directory is used.
47       * @return the newly created process.
48       * @throws IOException if trying to change directory.
49       */
50      Process exec(final CommandLine commandLine, final Map<String, String> env, final File workingDirectory) throws IOException;
51  
52      /**
53       * Tests whether {@code exitValue} signals a failure on the current system (OS specific).
54       * <p>
55       * <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
56       * 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
57       * signals a failure on OpenVMS. So if you execute a new Java VM on OpenVMS, you cannot trust this method.
58       * </p>
59       *
60       * @param exitValue the exit value (return code) to be checked.
61       * @return {@code true} if {@code exitValue} signals a failure.
62       */
63      boolean isFailure(final int exitValue);
64  }