Macaulay2 » Documentation
Packages » Macaulay2Doc :: runProgram
next | previous | forward | backward | up | index | toc

runProgram -- run an external program

Synopsis

Description

This method runs an external program which has already been loaded using findProgram. The results of this run are available in a ProgramRun object.

i1 : gfan = findProgram("gfan", "gfan --help")

o1 = gfan

o1 : Program
i2 : runProgram(gfan, "_version")

o2 = 0

o2 : ProgramRun
i3 : oo#"output"

o3 = Gfan version:
     gfan0.6.2

     Forked from source tree on:
     1506606121 Thu Sep 28 15:42:01 2017

     Linked libraries:
     GMP 6.2.1
     Cddlib       YES
     SoPlex        NO
     Singular      NO
i4 : runProgram(gfan, "_foo", RaiseError => false)

o4 = 256

o4 : ProgramRun
i5 : oo#"error"

o5 = UNKNOWN OPTION: _foo.
     USE --help AS A SINGLE OPTION TO VIEW THE HELP TEXT.

The value corresponding to the "output" key may also be obtained using toString.

i6 : toString runProgram(gfan, "_version")

o6 = Gfan version:
     gfan0.6.2

     Forked from source tree on:
     1506606121 Thu Sep 28 15:42:01 2017

     Linked libraries:
     GMP 6.2.1
     Cddlib       YES
     SoPlex        NO
     Singular      NO

It is also possible to skip findProgram and just provide two strings: the name of the program and the command line arguments.

i7 : runProgram("normaliz", "--version")

o7 = 0

o7 : ProgramRun
i8 : peek oo

o8 = ProgramRun{command => /usr/bin/normaliz --version                                          }
                error => 
                output => Normaliz 3.8.9
                          Copyright (C) 2007-2019  The Normaliz Team, University of Osnabrueck.
                          This program comes with ABSOLUTELY NO WARRANTY; This is free software,
                          and you are welcome to redistribute it under certain conditions;
                          See COPYING for details.

                return value => 0

Internally, this routine uses run. Another method to interact with programs is get.

i9 : get "!gfan _version"

o9 = Gfan version:
     gfan0.6.2

     Forked from source tree on:
     1506606121 Thu Sep 28 15:42:01 2017

     Linked libraries:
     GMP 6.2.1
     Cddlib       YES
     SoPlex        NO
     Singular      NO

See also

Ways to use runProgram :

For the programmer

The object runProgram is a method function with options.