Steve Moyle
2004-06-15 20:19:24 UTC
Dear SWI-Prolog Gurus,
I am trying to run a prolog script from the command line (Linux running SWI-Prolog (Multi-threaded, Version 5.3.11) ), with particular agurments passed in a the command line..
To investigate how arguments are passed into SWI-Prolog I started by testing some code I found on the TWiki in the section "Can I make an executable?"
#!/usr/local/bin/pl -g main -s
main :-
current_prolog_flag(argv, Argv),
append(_, [--|Av], Argv), !,
main(Av).
main(Args) :-
format(' The arguments passed in were: ~w~n', [Args]).
/* end script_params.pl */
Now when I chmod +x and run this I get:
$ ./script_params.pl -- fart face
ERROR: Prolog initialisation failed:
ERROR: script_file `--' does not exist
If I call prolog directly (not as a script) I get:
$ pl -s script_params.pl -- fart face
% script_params.pl compiled 0.01 sec, 2,708 bytes
The arguments passed in were: [--, fart, face]
?-
What I had hoped for was something like:
$ ./script_params.pl -- fart face
The arguments passed in were: [fart, face]
Please suggest how this might be made to work.
Cheers,
I am trying to run a prolog script from the command line (Linux running SWI-Prolog (Multi-threaded, Version 5.3.11) ), with particular agurments passed in a the command line..
To investigate how arguments are passed into SWI-Prolog I started by testing some code I found on the TWiki in the section "Can I make an executable?"
#!/usr/local/bin/pl -g main -s
main :-
current_prolog_flag(argv, Argv),
append(_, [--|Av], Argv), !,
main(Av).
main(Args) :-
format(' The arguments passed in were: ~w~n', [Args]).
/* end script_params.pl */
Now when I chmod +x and run this I get:
$ ./script_params.pl -- fart face
ERROR: Prolog initialisation failed:
ERROR: script_file `--' does not exist
If I call prolog directly (not as a script) I get:
$ pl -s script_params.pl -- fart face
% script_params.pl compiled 0.01 sec, 2,708 bytes
The arguments passed in were: [--, fart, face]
?-
What I had hoped for was something like:
$ ./script_params.pl -- fart face
The arguments passed in were: [fart, face]
Please suggest how this might be made to work.
Cheers,