# How to send the console text to a file?

**URL:** <https://swi-prolog.discourse.group/t/how-to-send-the-console-text-to-a-file/9298>\
**Category:** Help!\
**Created:** [September 18, 2025, 5:29pm UTC](https://swi-prolog.discourse.group/t/how-to-send-the-console-text-to-a-file/9298 "2025-09-18T17:29:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![martin](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@martin](https://swi-prolog.discourse.group/u/martin)\
**Post date:** [September 18, 2025, 5:29pm UTC](https://swi-prolog.discourse.group/t/how-to-send-the-console-text-to-a-file/9298/1 "2025-09-18T17:29:05Z")

</div>

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.

```prolog
% your code here

```

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [September 18, 2025, 5:49pm UTC](https://swi-prolog.discourse.group/t/how-to-send-the-console-text-to-a-file/9298/2 "2025-09-18T17:49:27Z")

</div>

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)](https://www.man7.org/linux/man-pages/man1/script.1.html) – 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)`.`

---

<div class="post-metadata">

**Author:** ![martin](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@martin](https://swi-prolog.discourse.group/u/martin)\
**Post date:** [September 18, 2025, 5:58pm UTC](https://swi-prolog.discourse.group/t/how-to-send-the-console-text-to-a-file/9298/3 "2025-09-18T17:58:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![martin](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@martin](https://swi-prolog.discourse.group/u/martin)\
**Post date:** [September 18, 2025, 6:02pm UTC](https://swi-prolog.discourse.group/t/how-to-send-the-console-text-to-a-file/9298/4 "2025-09-18T18:02:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [September 18, 2025, 6:10pm UTC](https://swi-prolog.discourse.group/t/how-to-send-the-console-text-to-a-file/9298/5 "2025-09-18T18:10:05Z")

</div>

> [@martin](#):
>
> your suggestion, “term(1)”

That should be `script(1)` of course.

---

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [September 18, 2025, 6:20pm UTC](https://swi-prolog.discourse.group/t/how-to-send-the-console-text-to-a-file/9298/6 "2025-09-18T18:20:55Z")

</div>

> 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?](https://swi-prolog.discourse.group/t/protocol-1-used-to-capture-screen-to-file/675)

* * *

FYI

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

 ![image](https://global.discourse-cdn.com/free1/uploads/swiprolog/original/2X/5/5e861d061c523acd9d2287343f9a7273ee864bda.png)

---

<div class="post-metadata">

**Author:** ![martin](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@martin](https://swi-prolog.discourse.group/u/martin)\
**Post date:** [September 18, 2025, 6:31pm UTC](https://swi-prolog.discourse.group/t/how-to-send-the-console-text-to-a-file/9298/7 "2025-09-18T18:31:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![brebs](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@brebs](https://swi-prolog.discourse.group/u/brebs)\
**Post date:** [September 20, 2025, 11:58am UTC](https://swi-prolog.discourse.group/t/how-to-send-the-console-text-to-a-file/9298/8 "2025-09-20T11:58:46Z")

</div>

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