From jan@swi.psy.uva.nl Wed Jun 27 17:11:56 2001
Received: from gollem.swi.psy.uva.nl (root@gollem [145.18.152.30])
	by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id f5RFBuc17291;
	Wed, 27 Jun 2001 17:11:56 +0200 (MET DST)
Received: from localhost (localhost [[UNIX: localhost]])
	by gollem.swi.psy.uva.nl (8.11.2/8.11.2/SuSE Linux 8.11.1-0.5) id f5RFBtt12160;
	Wed, 27 Jun 2001 17:11:55 +0200
From: Jan Wielemaker <jan@swi.psy.uva.nl>
Organization: SWI, University of Amsterdam
To: Paul Singleton <p.singleton@keele.ac.uk>, prolog@swi.psy.uva.nl
Subject: Re: [SWIPL] how to write on the standard error ?
Date: Wed, 27 Jun 2001 16:57:39 +0200
X-Mailer: KMail [version 1.0.29.2]
Content-Type: text/plain
References: <200106262116.f5QLGTB32528@gollem.swi.psy.uva.nl> <3B39F188.AA93DDCB@keele.ac.uk>
In-Reply-To: <3B39F188.AA93DDCB@keele.ac.uk>
MIME-Version: 1.0
Message-Id: <01062717115503.03816@gollem>
Content-Transfer-Encoding: 8bit

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.

