简体   繁体   English

如何重定向用SWIG包装并暴露给Python的C ++例程的标准流?

[英]How do you redirect a standard stream of a C++ routine wrapped with SWIG and exposed to Python?

Is it possible to control the standard streams of C++ code in python? 是否可以在python中控制C ++代码的标准流? The code is wrapped with SWIG and then exposed to Python where I call one of its functions. 该代码用SWIG包装,然后公开给Python,在这里我称之为函数之一。

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, eg devnull from the os module. 我收到来自C ++代码的各种有害消息,我想通过不使用输出流或将其重定向到位存储桶(例如,来自os模块的devnull)来抑制它们。

我认为最好的方法是在扩展的C或C ++中实现一个简单的函数/方法来重定向stdout输出,例如,请参见dup ,我认为它将很好地工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM