|
<< Click to Display Table of Contents >> RUN |
![]() ![]()
|
The RUN statement runs a program file containing Gekko statements. The default extension for Gekko program files is .gcm. With a statement like run test;, Gekko will look for test.gcm in the working folder. If not found, it will additionally look in the folders designated with option folder command = ... etc. A Gekko .gcm file may run other .gcm files in a nested fashion.
Use // to out-comment a line, or /* ... */ to out-comment several lines. You may also turn off a section of statement with an IF ... END, or you may leave a .gcm file early with RETURN. To stop Gekko completely, also returning from any 'parent' .gcm files, use STOP. (STOP is also practical for debugging: after the STOP, you may inspect variable values).
See also FUNCTION or PROCEDURE, which can be thought of as a program file that also can accept arguments. If you need to call a program file many times, for instance from inside of a loop, calling a function/procedure instead will often run much faster because of the lack of re-parsing and re-compiling. You may use a LIBRARY to store and organize functions/procedures, and libraries can store normal .gcm files, too.
You may run statements without using the Gekko graphical user interface directly, either via Gekko.exe or via remote control (cf. below).
RUN filename;
filename |
Filenames may contain an absolute path like c:\projects\gekko\bank.gbk, or a relative path \gekko\bank.gbk. Filenames containing blanks and special characters should be put inside quotes. Regarding reading of files, files in libraries can be referred to with colon (for instance lib1:bank.gbk), and "zip paths" are allowed too (for instance c:\projects\data.zip\bank.gbk). See more on filenames here. The extension .gcm is automatically added, if it is missing. If the filename is set to '*', you will be asked to choose the file in Windows Explorer. |
Tip: if you need to stop execution at a specific point/line to inspect variables etc., try inserting a STOP statement. This will abort from all called program files/procedures/functions, without executing anything more after the STOP (this is not the case regarding RETURN). Therefore, STOP can be practical for debugging, etc.
You may run the program file scenario.gcm like this:
RUN scenario; |
Or, if located in the sub-folder \scenarios:
RUN scenarios\scenario1; |
This will run scenario1.gcm in the subfolder \scenarios (relative to the working folder). You may also use a wildcard * to open a dialog box for choosing the .gcm file:
RUN *; |
The extension .gcm is added automatically if not provided. Other extensions may be used:
RUN gekko.ini; |
will run the gekko.ini file (same as the INI statement).
This is for more advanced users, but you may call Gekko.exe with parameters, if you need to run Gekko sessions as batch jobs. The location of Gekko.exe can be found via the Gekko menu: Help --> About... under 'Program folder'. Use this Gekko.exe location, and indicate a working folder, like the following:
call "c:\Program Files\Gekko\Gekko.exe" "-folder:c:\Gekkotest" "-noini" "run r1.gcm; exit;" |
This code can be issued from for instance a Windows CMD window. Here, Gekko is located in the folder c:\Program Files\Gekko, and the working folder is c:\Gekkotest. Any gekko.ini file in that working folder is skipped (-noini), and finally the two statements in the last quoted block are executed (run r1.gcm; exit;). In this case, the program file r1.gcm is run, and after this, Gekko is closed with the EXIT statement (if this is omitted, the Gekko window will persist, and you will have to close it manually). You may inser any Gekko statements, separated by semicolons (;). In the absence of a -noini parameter, Gekko will first run a possible gekko.ini file from the working folder, and then run any Gekko statements. To make Gekko run completely behind the scences ("stealth") without opening the graphical user interface at all, you may use the -hide parameter. Gekko will generally produce a gekkooutput.txt file for the user to inspect afterwards (for instance to inspect error messages). This file will not be generated if the -nolog parameter is used.
You may put code like the above in a batch file (.bat) that can be started simply by double-clicking it. If the CMD window is located at the Gekko.exe folder, you may alternatively use the following simpler code:
Gekko.exe -folder:c:\User\Gekkotest -noini run r1.gcm; exit; |
But calling Gekko.exe in this way is prone to problems with blank spaces in for instance folder or filenames. Therefore, using call with quotes (") is recommended.
Calling Gekko.exe from for instance a R or Python session is possible, but note that the inverse is also possible, calling R or Python from Gekko (cf. R_RUN and PYTHON_RUN). If you need to call Gekko from Excel, see the Gekcel project.
With option interface remote = yes;, Gekko may be remote-controlled from a special remote.gcm program file in the working folder (cf. the description under OPTION). This is handy if you need to remote-control an existing Gekko instance from some other program, for instance a text editor. The above-mentioned Gekko.exe parameters starts up a new Gekko instance, so you can use remote control to avoid that. You may try the following:
1.Start up Gekko normally
2.Type option interface remote = yes;
3.With an external text editor create a file named remote.gcm, containing the line tell 'Hello from remote control';. Put this file in the Gekko working folder.
4.Try changing the TELL line in remote.gcm to something else: Gekko will respond to that change.
Note that if you start with (3) above, and then fire up Gekko, Gekko will not run the remote.gcm file. Gekko only reacts when it detects changes in such a file.
If you need to run the same piece of code many times (for instance inside a loop), consider using a PROCEDURE (or FUNCTION) instead of calling RUN on a file. Running a .gcm file entails some fixed loading, parsing and compiling costs each time it is called. These costs are not present when using a procedure (only when it is loaded, not when called).
Instead of EDIT, most people use a 'real' external text editor like for instance VS Code or Sublime Text to edit Gekko program files (.gcm). For VS Code, see its integrated Gekko extension (developed by the Gekko editor): see under 'Extensions' and search for 'Gekko'. For Sublime Text, see these open-source modules for Sublime and Gekko integration (including remote control).
option folder command = '';
option folder command1 = '';
option folder command2 = '';
option folder working = '';
option interface debug = dialog;
option interface edit style = gekko;
option interface errors = normal;
option interface remote = no;
option interface remote file = '';
option interface sound = no;
option interface sound type = bowl;
option interface sound wait = 60;
option interface suggestions = option;
lhsRhs()
EDIT, FUNCTION, LIBRARY, PIPE, PROCEDURE, PYTHON_RUN, RETURN, R_RUN, STOP, SYS