public static String findExecutableByNameInPATH()

in cmake-runner-agent/src/jetbrains/buildServer/cmakerunner/agent/util/FileUtil2.java [28:52]


  public static String findExecutableByNameInPATH(@NotNull final String exeName,
                                                  @NotNull final Map<String, String> environment) {
    final String path = OSUtil.getPathEnvVariable(environment);
    if (path != null) {
      final StringTokenizer st = new StringTokenizer(path, File.pathSeparator);

      //tokens - are pathes with system-dependent slashes
      while (st.hasMoreTokens()) {
        final String possible_path = st.nextToken() + "/" + exeName;
        if (FileUtil2.checkIfExists(possible_path)) {
          return possible_path;
        }
      }
    }

    if (SystemInfo.isWindows && !exeName.endsWith(".exe") && !exeName.endsWith(".bat")) {
      String deep;
      deep = findExecutableByNameInPATH(exeName + ".exe", environment);
      if (deep == null) {
        deep = findExecutableByNameInPATH(exeName + ".bat", environment);
      }
      return deep;
    }
    return null;
  }