User Tools

Site Tools


gams:call_gams_within_gams

How do I call GAMS within GAMS

There are various options to execute GAMS (or other programs) within GAMS:

  • during compilation: $call 'external program'
  • during execution: execute 'external program';

Note: $call 'external program' calls the shell to execute you command and shell commands like redirection (>) or piping (|) are possible. $call '=external program' calls a single executable without using the shell. In most cases you can use just $call 'external program', but is a slight overhead with the shell call.

The Bruce McCarl User Guide features some nice information about this, please search for: “Executing an external program” and “Executing an external program”. If you are using the Windows version, you will find the Mc Carl User Guide at: Help → Expanded GAMS Guide (Mc Carl). Please also have a look at this entry: “User defined Functions or Subroutines”.

Within the optimization (while the solver is running) you can:

Please note the log of a model if called by $call =gams your_model.gms or execute “gams trnsport.gms”; will be invisible and lost after the model run. To avoid this, just add the following lines to you model to echo the log file into the process window or the console (if GAMS is executed via the command line).

$setglobal ide "ide=%gams.ide% lo=%gams.lo% errorlog=%gams.errorlog% errmsg=1"
$call =gams your_model.gms %ide%
$if errorlevel 1 $abort your_model failed
$setglobal ide "ide=%gams.ide% lo=%gams.lo% errorlog=%gams.errorlog% errmsg=1"
execute "gams your_model.gms %ide%";
abort$errorlevel 'your_model failed';
gams/call_gams_within_gams.txt · Last modified: 2017/09/02 17:07 by support