I examined my code and I realised that after closing the output stream I had not restored the default stream back to user_output. This appears to be the cause of the blowout. If I run this modified code:
This works as expected:
| ?- testing(C), format('~s~n',[C]).
C = [71,69,84,32,47,109,121,47,115,108,105,112,112,101,114,115,47,110,111,119,47,106,101,101,118,101,115,13,10]
In the documentation for close/2, close/1 it says:
If SorA is the current output stream the current output stream becomes the standard output stream user_output.
I couldn’t determine what close_output_codes_stream/2 does and so it would seem that the user_output stream was in some indeterminate value?
Hope that helps track it down.
Many thanks again to Daniel and his Elves for GNU Prolog and a Merry Christmas everybody out there that buys into that particular scheme etc.