Node:Interfacing with UNIX, Next:, Up:Interfacing with Other Languages



Interfacing with UNIX

Question: [UNIX]
How can I turn a Prolog source file into a UNIX script, to be invoked from the command line or from a Web application, for example?

Wrap the file into an executable Shell script that simply invokes SICStus. Informational messages can be filtered out by redirecting stderr to /dev/null. For example:

#!/bin/sh
exec sicstus 2> /dev/null -f -a "$@" <<EOF

% Tell SICStus to consult the sources.
% The embedded command invokes main(Args)
% where Args is the script's arguments passed as a list of atoms.

[user].

main(Args) :-
    format('Hello world!\n\c
            Invoked with args = ~q\n', [Args]).

:-
	prolog_flag(argv, Args), main(Args).
EOF

The above script can be invoked as follows:

% ./hw.sh a 236U ka=ka
Hello world!
Invoked with args = [a,'236U','ka=ka']