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.