开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜