Simplest way to redirect write statements to a file from the console window?

I’m using: SWI-Prolog version 8.1.9.

Is there a simple way to temporarily redirect or echo (either is fine) all write and nl activity to a disk file? If not, what are the SWI-Prolog equivalents for the usual fopen/fwrite/fclose/etc. statements in other languages? I need to write a bunch of text to a file and I’ve never done file I/O in SWI-Prolog. I skimmed the manual but all I found so far is the file predicate, and I’m not sure how to use that to do file I/O.

If there’s a section in the manual that deals with this, please link me.

I believe you want with_output_to. There is also open/4, which gives you a stream you can pass to format/3 (e.g. open("f.txt", write, Stream, []), format(Stream, "Hello!~n", []).)

1 Like

jamessnvc already addressed the main builtins, so, another hint - not sure it fills your needs - but take a look to protocol

1 Like

See: Wiki: How to - protocol/1

1 Like