Subject: Re: [SWIPL] how to write on the standard error ?

From: Jan Wielemaker <[email-masked]>
Date: Wed, 27 Jun 2001 16:57:39 +0200

On Wed, 27 Jun 2001, Paul Singleton wrote:
>Jan Wielemaker wrote:
>
>> The Prolog stream for stderr is called user_error.
>
>BTW is there anything special about user_error, apart from there not
>being a current_error/1 or set_error/1?  Could there be?

Its not buffered in the good old Unix tradition, which means that
if you send it an incomplete line it will actually emit this
immediately.

You can manipulate it in several ways.  For a start, you rebind
the user_error alias to a new stream.  So if you do:

?- open_null_stream(X),
   set_stream(X, alias(user_error)).

all error output is discarded.  At the moment there is
no way to find the $stream/1 term for user_error, so you
can't switch it back.  Maybe that should be added to to
stream_property/2.

Using set_stream/2 is done in library(threadutil) to give
each thread its own console with its own user streams
(if you want to give a thread a console).

An alternative is to use the foreign language interface
and replace the low-level I/O functions of Serror (as it
is called there) to whatever you like.  This happens for
example in plwin.exe.

Normally, sending messages elsewhere is achieved using
message_hook/3, or the rather new flag -q, which can
be controlled from inside your program using the flag
verbose.

In 4.0.7 you can play some more tricks with set_stream/2.

	--- Jan

P.s.	None of this is covered by any standard.