Module File.Command

Functions to find executable programs, possibly in $PATH.

val hits : ?path:string -> string -> string list

(hits ?path name) returns a list of the programs named "name" in path.

Only an implicit name (see Filename.is_implicit) is looked up in path; a non-implicit name is returned iff it is executable and a plain file.

Commands are returned in the order in which they are found in path.

The default value for path is (Sys.getenv "PATH").

Example:

  • hits "true" = ["/bin/true";"/usr/bin/true"]

Invariant: (Filename.is_implicit name && executable name) implies (len (hits name) = 1)

val exists : ?path:string -> string -> bool

(exists ?path name) is (hits ?path name |> len > 0).

val first : ?path:string -> string -> string option

(first ?path name) returns (Some fn) where fn is (hd (hits ?path name)), or else is None.