How to send the console text to a file?

I’m using: SWI-Prolog version 9.3.30.

Is there a way to send the text from the SWI Prolog console to a file?

Or from the Linux Terminal to a file?

This is so that I can keep a record of what I entered at the “?-” prompt,

and what the responses were.

For example, the file might contain the following.

?- true.

true.

?- hello_world.

Hello.

true.

?- halt.

% your code here

If you run swipl in an Emacs shell, you can save the contents with C-x C-s or C-x C-w.

If you’re running on an ordinary terminal, see script(1) – it’s one of a number of ways of capturing output (and some terminal programss have a menu item for saving the output).

EDIT: fixed the name of the command; it’s script(1)`.

I know I can copy the text using Ctrl+C. But that is not what I need.

What I want is to have the text saved to a file as soon as it appears. This is so that if my operating system crashes, and reboots, I won’t lose the text that was in the Terminal, or the SWI Console.

That way if I spend a lot of time testing and debugging my code, and I have a lot of code tests in a Terminal, then it won’t all be forgotten if the operating system crashes. I know the operating system doesn’t crash often, but it happened recently when I ran out of RAM.

I just looked at your suggestion, “term(1)”. That may be what I need, I will try it out. Thank you.

I have a vague memory that there is a prolog predicate to do something similar, but I can’t manage to remember what it is called.

That should be script(1) of course.

Is there a way to send the text from the SWI Prolog console to a file?

This might be what you seek:

Is there a way to send the text from the SWI Prolog console to a file?


FYI

This is a Discourse forum which includes below each topic a list of related topics.

Yes, that’s it, “protocol/1”.
Thank you.

1 Like

You probably want protocola/1 instead, to prevent overwriting the text file if it already exists.