Re: Non-interactive swiprolog queries from the shell
Daniel Lyons <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
Antonios Antoniadis writes: > Hello everyone, > > I started building the left hemisphere of my robot's brain with swi-prolog > and I'm stuck on probably a very basic thing as I haven't touched prolog since uni. I want to execute/pass/pipe/whatever queries into > swi-prolog from the GNU/Linux shell and save/use the results. I can run any shell command via the shell itself or python but do you have any ideas on how/what > should I run (syntax) to e.g. have swi-prolog use a specific file with my > stored rules or whatever (complied I guess) and pass the query like an > argument or input? Actually, is this possible at all? > > So, non-interactive queries from the command line is what I'm looking for here. You can specify goals on the command line with -g. I usually write a little wrapper script I use when I need to make a Prolog program seem like a Unix script, and the last line will look like: swipl -q -l loader -g main -t 'halt(0)' -- $* where 'main' is an arity-0 goal somewhere in the sources, probably loaded by loader. The $* lets you pass arguments on to swipl to be handled by the option parsing framework. -- Daniel Lyons