Home Contents Index Summary Previous Next

2.3 Initialisation files and goals

Using commandline arguments (see section 2.4), SWI-Prolog can be forced to load files and execute queries for initialisation purposes or non-interactive operation. The most commonly used options are -f file or -s file to make Prolog load a file, -g goal to define an initialisation goal and -t goal to define the toplevel goal. The following is a typical example for starting an application directly from the commandline.


machine% pl -f load.pl -g go -t halt

It tells SWI-Prolog to load load.pl, start the application using the entry-point go/0 and ---instead of entering the interactive toplevel--- exit after completing go/0. The -q may be used to supress all informational messages.

In MS-Windows, the same can be achieved using a short-cut with appropriately defined commandline arguments. A typically seen alternative is to write a file run.pl with content as illustrated below. Double-clicking run.pl will start the application.


:- [load].                      % load program
:- go.                          % run it
:- halt.                        % and exit

Section 2.10.2.1 discusses further scripting options and chapter 6 discusses the generation of runtime executables. Runtime executables are a mean to deliver executables that do not require the Prolog system.