Save output from Prolog execution
I am running a tool in Prolog, and after I execute it, the result will appear on the screen, inside the Prolog shell. How can I copy this result into another file开发者_开发技巧?
you never said what prolog interpreter you're using. This code works for Edinburgh-compatible version of Prolog, SWI-Prolog (on Fedora) in my case.
if you have a file hello.pl:
hello_world :- write('Hello World!').
then
consult('hello').
qsave_program(hello,[stand_alone(true),goal(hello_world)]).
quit interpreter and in the shell:
$chmod +x hello
./hello > output_file
it doesn't return to shell when it's done, so you need to find a way to check whether or not your program finished execution and then Ctrl-d and check your output_file hope this helps
From the command line you can do this:
script <file Name>
run your prolog program
exit
精彩评论