[C++-sig] Redirecting stdout for B.P extensions?
Hubert Holin
Hubert.Holin at meteo.fr
Wed Sep 14 17:46:41 CEST 2005
Somewhere in the E.U., le 14/09/2005
Bonjour
In a (perhaps perverse) project involving Objective-C
(Cocoa), Python and C++, I have run into a difficulty for which I
know an unpleasant workaround, and for which I am looking for a
gentler cure.
In essence, at some point a Python script is calling a
function which is actually coded in C++ using Boost.Python (and began
life as part of a terminal tool). Prior to the call, I redirect
Python's output stream (by assigning to sys.stdout). From that point
onward, Python does print where it is told to, but C++ code within
the extension which "<<"'s to ::std::cout is not redirected (apart
from that, the whole shebang works nicely).
As I have full control over the C++ code, I can add another
parameter to the extension function's call to represent the
destination of outputs, and recode all over the place. That's the
unpleasant workaround. What I would like would be for a mechanism to
tell the extension to actually use Python's current sys.stdout. At
any rate, there will necessarily come a time when I will use some C++
code over which I will *not* have control, so a general cure would be
best...
Merci
Hubert Holin
P.S.: sorry, I found no way to search the archive... pointers to that
welcome as well!
More information about the Cplusplus-sig
mailing list