views:

47

answers:

1

Hi. I am trying to call a prolog program and receive output into my bash script.

Currently I am using the extremely crude version of using halt(0) or halt(1) and then examining the exit code in bash, using 0 as true and 1 as false to the question my prolog program answers. Is there a better way to handle output? I am using gnu prolog. I guess I could redirect std into a variable or something, but g-prolog outputs alot of nonsense, such as disclaimer. Any ideas? :)

+1  A: 

Use

gprolog --init-goal "<your_goal>,halt"

to avoid GNU Prolog's default output. Other systems have similar switches.

mat
@mat Thanks, that ALMOST did the trick. I still get output from the compiler though.. I use gprolog --init-goal "[file], my_goal(), halt". Any idea how to remove that output?
Max Malmgren
Pipe the output through `tail -n +3`. I just scanned the GNU Prolog manual, and there seems to be no other way (except through C). Make sure your program succeeds, or you'll get into the REPL. I've had the same problem with other Prologs; never understood why none of them supports this use case.
larsmans
@larsmans or mat: If I compile my program using gplc, is it possible to accomplish the same thing? --init-goal does not seem to work.
Max Malmgren