2 Overview
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
      • Overview
        • Getting started quickly
        • The user's initialisation file
        • Initialisation files and goals
        • Command line options
        • UI Themes
        • GNU Emacs Interface
        • Online Help
        • Command line history
        • Reuse of top-level bindings
        • Overview of the Debugger
        • Compilation
        • Environment Control (Prolog flags)
        • An overview of hook predicates
        • Automatic loading of libraries
        • Packs: community add-ons
        • The SWI-Prolog syntax
        • Rational trees (cyclic terms)
        • Just-in-time clause indexing
        • Wide character support
        • System limits
        • SWI-Prolog and 64-bit machines
        • Binary compatibility
    • Packages

2.3 Initialisation files and goals

Using command line 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 initialisation goals and -t goal to define the top-level goal. The following is a typical example for starting an application directly from the command line.

machine% swipl -s 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 top level--- exit after completing go/0 .

The command line may have multiple -g goal occurrences. The goals are executed in order. Possible choice points of individual goals are pruned. If a goal fails execution stops with exit status 1. If a goal raises an exception, the exception is printed and the process stops with exit code 2.

The -q may be used to suppress all informational messages as well as the error message that is normally printed if an initialisation goal fails.

In MS-Windows, the same can be achieved using a short-cut with appropriately defined command line 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.11.2.1 discusses further scripting options, and chapter 14 discusses the generation of runtime executables. Runtime executables are a means to deliver executables that do not require the Prolog system.