> < ^ Date: Wed, 05 Mar 1997 10:54:29 +0100
> < ^ From: Alexander Hulpke <hulpke@math.colostate.edu >
< ^ Subject: Re: external programs

Dear Forum,

Chris Charnes asked:

Is there a way to
call external programs from within Gap?

Yes. Provided you have a reasonable operating system (e.g. UNIX) you can use
'Exec'. The manual (Section 3.22, about page 308) tells you more.
Note, however that passing information from the external program back to
GAP requires the external program to write the output as GAP assignment
statements to a file and GAP
reading in this file via 'Read' afterwards. You will also have to deal with
selection of appropriate filenames, write permissions &c. yourself.

For example, if 'foo' is a program that adds the first two arguments and
writes the result in GAP readable format to a file given in the third
argument, your GAP code could look like:

Exec("foo 3 5 bar");
Read("bar");

This would call the external program 'foo' with the arguments 3 5 and 'bar'.
Then the external program would use the third argument as a filename to
write output to. So it might create a file 'bar' that looks like
GAPINPUT := 8;
Then GAP reads in the file and the variable GAPINPUT contains the result.
Note that GAPINPUT (or whatever variable you chose) must be a *global*
variable, even when calling the 'Read' from a function.

Best regards,

Alexander Hulpke


> < [top]