views:

117

answers:

1

Is it possible to control the standard streams of C++ code in python? The code is wrapped with SWIG and then exposed to Python where I call one of its functions.

I am getting all kinds of unwanted messages coming from C++ code and I want to suppress them either by not using the output stream or by redirecting it to a bit bucket, e.g. devnull from the os module.

+1  A: 

I think the best way is to implement a simple function/method in C or C++ of your extension to redirect the stdout output, see dup for example, I think it will work fine.

Tarantula
Even if not redirecting this to STOUT, you maybe could send it to some PIPE or other FD which python could handle. As to iostream, I think you'll have problems w/ that.
Petriborg