🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c++.moderated
Article #10

Re: Re-Routing streams

#10
From: J. Kanze
Date: Sat, 16 Dec 1995 15:39
31 lines
1940 bytes
X-Original-Date: 15 Dec 1995 14:21:37 +0100

Kyle Lussier (lussier@aviator.cis.ufl.edu) wrote:

|> How do I get re-route, or overload the standard streams to send output
|> to somewhere else?  Specifically I want all messages to stderr to be
|> sent to a file and all messages to stdout to be sent to a file.

Generally, this will be handled before invoking the program, in a system
dependant way.

Once the program is started, if your iostream library conforms to the
draft standard (precious few do), it is possible to modify the streambuf
that the stream uses, thus:

    filebuf     logFile( "logfile.name" ) ;
    cerr.rdbuf( &logFile ) ;

This is just a quick example.  Obviously, you will probably want some
error handling.  And being a bit paranoid, I would probably save the
preceding streambuf*, and restore it at program end.
-- 
James Kanze           (+33) 88 14 49 00          email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
Conseils, études et réalisations en logiciel orienté objet --
              -- A la recherche d'une activité dans une region francophone

    [ comp.lang.c++.moderated is a moderated newsgroup.  Submit articles ]
    [  to <c++-submit@netlab.cs.rpi.edu>.  The moderation policy can be  ]
    [   retrieved from <http://netlab.cs.rpi.edu/~cppmods/guide.html>.   ]
    [    Moderators can be reached at: c++-request@netlab.cs.rpi.edu.    ]
Technical Details
Message-ID: <4aup7t$ipe@netlab.cs.rpi.edu>
Path: arc1-ca.pugleaf.net!kbad.eglin.af.mil!rpi!not-for-mail
References: <4aq1ig$1u2@netlab.cs.rpi.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!kbad.eglin.af.mil!rpi!not-for-mail
From: kanze@gabi-soft.fr (J. Kanze)
Newsgroups: comp.lang.c++.moderated,comp.lang.c++
Subject: Re: Re-Routing streams
Followup-To: comp.lang.c++.moderated,comp.lang.c++
Date: 16 Dec 1995 15:39:41 -0000
Organization: GABI Software, Sarl.
Sender: cppmods@netlab.cs.rpi.edu
Approved: harkness@airmail.net
Message-ID: <4aup7t$ipe@netlab.cs.rpi.edu>
References: <4aq1ig$1u2@netlab.cs.rpi.edu>
NNTP-Posting-Host: netlab.cs.rpi.edu