User Tools

Site Tools


How can I access environment variables inside GAMS

Starting with distribution 21.6 GAMS gives you direct access to environment variable at compile time via %sysenv.varname%. For example %sysenv.windir% provides the Windows directory on your PC.

In versions before 21.6, there is no direct way of accessing the environment variables inside GAMS, but we can create an include file on the fly that sets GAMS compile time strings which contain the settings of a system environment variable:

  • for Windows:
$echon '$setglobal WINDIR '  > setwindir
$call echo %WINDIR%         >> setwindir
$include setwindir
display "%windir%";
  • for Unix:
$echon '$setglobal USER '    > setuser
$call echo $USER            >> setuser
$include setuser

display "%USER%"
gams/how_can_i_access_environment_variables_inside_gams.txt · Last modified: 2014/11/18 04:30 by admin