Home > Archive > Prolog > April 2004 > SWI-prolog, runtime, how-to
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
SWI-prolog, runtime, how-to
|
|
| Will Briggs 2004-04-13, 1:40 pm |
| Sorry, I tried a different search term after posting my query (which I
can't make this a reply to on Google groups). Here was the answer:
main :-
|> unix(argv(Argv)), % still Quintus compatibility
|> append(_, [--|AppArgs], Argv), !,
|> parse(AppArgs),
|> halt.
|>
|> parse(Argv) :-
|> format('Called with argv ~w~n', [Argv]).
|> % pl -o test -f none -g main -c load.pl
|> load.pl compiled, 0.00 sec, 1,312 bytes.
|> /staff/jan/lib/pl-3.2.8/library/quintus compiled into quintus,
|> 0.00 sec, 9,792 bytes.
|> % ./test hello world
|> Called with argv [hello, world]
|> %
from http://groups.google.com/groups?q=s...inria.fr&rnum=1
| |
| Jan Wielemaker 2004-04-13, 4:35 pm |
| In article <b2180865.0404130833.39392a4c@posting.google.com>, Will Briggs wrote:
> Sorry, I tried a different search term after posting my query (which I
> can't make this a reply to on Google groups). Here was the answer:
>
> main :-
>|> unix(argv(Argv)), % still Quintus compatibility
You can also use current_prolog_flag(argv, Argv), which is the basic
mechanism to get the argument vector. There are a few other Prolog
systems using this API.
This, like qsave_program/2, generates a saved-state. On Linux the default
is to use a little /bin/sh script. Using the option --stand_alone=true
(or stand_alone(true) for qsave_program/2) the emulator itself is added
in front of the saved-state, resulting in a single-file executable that
requires no other files at runtime (unless you explictely try to load
Prolog resources during the execution of your program of course).
For small things on systems where it is no problem to have Prolog
installed, use scripts using the #! notation. Smaller and easier!
--- Jan
>|> append(_, [--|AppArgs], Argv), !,
>|> parse(AppArgs),
>|> halt.
>|>
>|> parse(Argv) :-
>|> format('Called with argv ~w~n', [Argv]).
>
>|> % pl -o test -f none -g main -c load.pl
>|> load.pl compiled, 0.00 sec, 1,312 bytes.
>|> /staff/jan/lib/pl-3.2.8/library/quintus compiled into quintus,
>|> 0.00 sec, 9,792 bytes.
>|> % ./test hello world
>|> Called with argv [hello, world]
>|> %
>
> from http://groups.google.com/groups?q=s...inria.fr&rnum=1
|
|
|
|
|