next | previous | forward | backward | up | top | index | toc | Macaulay2 website
Macaulay2Doc :: findProgram

findProgram -- load external program

Synopsis

Description

This function checks for the existence of an external program by running cmd (or every element of cmds) prepended with various paths in the following order:

For each path, any prefixes specified by the Prefix option are checked.

Once this is successful (i.e., cmd or each element of cmds returns a value of 0), then a Program object is returned. If it is unsuccessful, then either an error is raised or null is returned, depending on the value of RaiseError.

Note that if a program consists of a single executable binary file, then name should coincide with the name of this file.

i1 : programPaths#"gfan" = "/path/to/gfan/"

o1 = /path/to/gfan/
i2 : gfan = findProgram("gfan", "gfan --help", Verbose => true)
checking for gfan in /path/to/gfan/...
    not found
checking for gfan in /usr/libexec/Macaulay2/bin/...
    not found
checking for gfan in /home/m2user/src/M2/M2/usr-build/bin/...
    not found
checking for gfan in /home/m2user/src/M2/M2/usr-build/bin/...
    not found
checking for gfan in /home/m2user/src/M2/M2/usr-build/bin/...
    not found
checking for gfan in /usr/local/Caskroom/miniconda/base/bin/...
    not found
checking for gfan in /home/m2user/bin/...
    not found
checking for gfan in /home/m2user/local/bin/...
    not found
checking for gfan in /usr/local/sbin/...
    not found
checking for gfan in /usr/local/bin/...
    not found
checking for gfan in /usr/sbin/...
    found

o2 = gfan

o2 : Program

One program that is shipped with a variety of prefixes in different distributions and for which the Prefix option is useful is TOPCOM:

i3 : findProgram("topcom", "cube 3", Verbose => true, Prefix => {
         (".*", "topcom-"),
         ("^(cross|cube|cyclic|hypersimplex|lattice)$", "TOPCOM-"),
         ("^cube$", "topcom_")})
checking for topcom in /usr/libexec/Macaulay2/bin/...
  trying prefix "" for executables matching ".*"...
    found

o3 = topcom

o3 : Program

Note that when using the MinimumVersion option, the command used to obtain the current version number must remove everything except the version number itself and any leading or trailing whitespace. Piping with standard UNIX utilities such as sed, head, tail, cut, and tr may be useful.

i4 : findProgram("gfan", "gfan --help", Verbose => true,
       MinimumVersion => ("0.5",
         "gfan _version | head -2 | tail -1 | sed 's/gfan//'"))
checking for gfan in /path/to/gfan/...
    not found
checking for gfan in /usr/libexec/Macaulay2/bin/...
    not found
checking for gfan in /home/m2user/src/M2/M2/usr-build/bin/...
    not found
checking for gfan in /home/m2user/src/M2/M2/usr-build/bin/...
    not found
checking for gfan in /home/m2user/src/M2/M2/usr-build/bin/...
    not found
checking for gfan in /usr/local/Caskroom/miniconda/base/bin/...
    not found
checking for gfan in /home/m2user/bin/...
    not found
checking for gfan in /home/m2user/local/bin/...
    not found
checking for gfan in /usr/local/sbin/...
    not found
checking for gfan in /usr/local/bin/...
    not found
checking for gfan in /usr/sbin/...
    found version 0.6.2 >= 0.5

o4 = gfan

o4 : Program

See also

Ways to use findProgram :

For the programmer

The object findProgram is a method function with options.