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

发布于 2024-09-03 18:02:30 字数 148 浏览 3 评论 0原文

是否可以在Python中控制C++代码的标准流?该代码用 SWIG 包装,然后暴露给 Python,我在其中调用其函数之一。

我收到来自 C++ 代码的各种不需要的消息,我想通过不使用输出流或将其重定向到位存储桶(例如来自 os 模块的 devnull)来抑制它们。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡笑忘祈一世凡恋 2024-09-10 18:02:31

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文