JAL-2937 working Cygwin bash execution of hmmbuild on Windows
[jalview.git] / src / jalview / util / FileUtils.java
index b81ec71..1684763 100644 (file)
@@ -37,6 +37,28 @@ public final class FileUtils
   }
 
   /**
+   * Answers the path to the folder containing the given executable file, by
+   * searching the PATH environment variable. Answers null if no such executable
+   * can be found.
+   * 
+   * @param cmd
+   * @return
+   */
+  public static String getPathTo(String cmd)
+  {
+    String paths = System.getenv("PATH");
+    // backslash is to escape regular expression argument
+    for (String path : paths.split("\\" + File.pathSeparator))
+    {
+      if (getExecutable(cmd, path) != null)
+      {
+        return path;
+      }
+    }
+    return null;
+  }
+
+  /**
    * A convenience method to create a temporary file that is deleted on exit of
    * the JVM
    *