How do you use GAP in batch mode?

351 Views Asked by At

I can't seem to figure out how to use the GAP computer algebra system (for example, if I have a python script, I can do python script.py > /tmp/python_output.csv) I can't seem to find any info in the GAP documentation [I am sure it is there somewhere])

2

There are 2 best solutions below

1
Max Horn On

Using gap script.g works fine, but it does not terminate GAP at the end, but rather switches to the REPL at the end. To change that, you can end your script with QUIT;. Or, if you use GAP >= 4.11.0, you can add -c 'QUIT;' at the end of the command line to achieve the same effect for any script, without modifying it.

In addition, you may want to turn off the banner with -b and enable quiet mode with -q. Finally, you can use --quitonbreak to disable the break loop so that errors terminate instead of resulting in a hang waiting for user input.

In summary:

gap --quitonbreak -b -q script.g

or if you don't want to end your script with QUIT;, use

gap --quitonbreak -b -q script.g -c 'QUIT;'

If you feel the need to do this a lot, you could wrap this into a little helper shell script gap-batch which looks something like this:

#!/bin/sh
gap --quitonbreak -b -q $* -c 'QUIT;'

If you put this into your PATH, then you can just do

gap-batch script.g
0
wkong On

I use unix redirection :

     gap -q < file.g

to run batch file. It works well.