保存 Prolog 执行的输出

发布于 2024-10-05 10:25:20 字数 72 浏览 0 评论 0原文

我正在 Prolog 中运行一个工具,执行后,结果将显示在 Prolog shell 内的屏幕上。如何将此结果复制到另一个文件中?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

八巷 2024-10-12 10:25:20

你从来没有说过你正在使用什么 prolog 解释器。
此代码适用于爱丁堡兼容版本的 Prolog,
就我而言,SWI-Prolog(在 Fedora 上)。

如果你有一个文件 hello.pl:

 hello_world :- write('Hello World!').

然后

consult('hello').
qsave_program(hello,[stand_alone(true),goal(hello_world)]).

退出解释器并在 shell 中:

$chmod +x hello
./hello > output_file

完成后它不会返回到 shell,所以你需要找到一种方法来检查你的程序是否完成执行,然后 Ctrl-d 和检查你的输出文件
希望这有帮助

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

柠栀 2024-10-12 10:25:20

从命令行您可以执行以下操作:

script <file Name>
run your prolog program
exit

From the command line you can do this:

script <file Name>
run your prolog program
exit
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文