Use absolute paths in ProcessBuilder invocations.

Needed for #276.

--
MOS_MIGRATED_REVID=114838538
diff --git a/src/main/java/com/google/devtools/build/lib/shell/Command.java b/src/main/java/com/google/devtools/build/lib/shell/Command.java
index 8d9cffc..794be92 100644
--- a/src/main/java/com/google/devtools/build/lib/shell/Command.java
+++ b/src/main/java/com/google/devtools/build/lib/shell/Command.java
@@ -178,10 +178,20 @@
 
   /**
    * Creates a new {@link Command} for the given command line elements. The
-   * command line is executed exactly as given, without a shell. The given
-   * environment variables and working directory are used in subsequent
+   * command line is executed without a shell.
+   *
+   * The given environment variables and working directory are used in subsequent
    * calls to {@link #execute()}.
    *
+   * This command treats the  0-th element of {@code commandLineElement}
+   * (the name of an executable to run) specially.
+   * <ul>
+   *  <li>If it is an absolute path, it is used as it</li>
+   *  <li>If it is a single file name, the PATH lookup is performed</li>
+   *  <li>If it is a relative path that is not a single file name, the command will attempt to
+   *       execute the the binary at that path relative to {@code workingDirectory}.</li>
+   * </ul>
+   *
    * @param commandLineElements elements of raw command line to execute
    * @param environmentVariables environment variables to replace JVM's
    *  environment variables; may be null
@@ -189,12 +199,20 @@
    * working directory is used
    * @throws IllegalArgumentException if commandLine is null or empty
    */
-  public Command(final String[] commandLineElements,
-                 final Map<String, String> environmentVariables,
-                 final File workingDirectory) {
+  public Command(
+      String[] commandLineElements,
+      final Map<String, String> environmentVariables,
+      final File workingDirectory) {
     if (commandLineElements == null || commandLineElements.length == 0) {
       throw new IllegalArgumentException("command line is null or empty");
     }
+
+    File executable = new File(commandLineElements[0]);
+    if (!executable.isAbsolute() && executable.getParent() != null) {
+      commandLineElements = commandLineElements.clone();
+      commandLineElements[0] = new File(workingDirectory, commandLineElements[0]).getAbsolutePath();
+    }
+
     this.processBuilder =
       new ProcessBuilder(commandLineElements);
     if (environmentVariables != null) {