是否可以在C ++中禁用stderr? [英] Is it possible to disable stderr in C++?

查看:198
本文介绍了是否可以在C ++中禁用stderr?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为libxml2编写了一个用于html解析的程序。虽然它做它的工作,html解析器写入大量的各种错误到stderr。是否可以全部禁用stderr(或重定向到/ dev / null,而不必使用重定向shell脚本来运行它)?

I wrote a program for linux using libxml2 for html parsing. Although it does its job, the html parser writes lots of various errors to stderr. Is it possible to disable stderr at all (or redirect it to /dev/null while not having to run it with a redirecting shell script)? I can live with having to write my own errors to stdout, I just want to get rid of these errors.

推荐答案

使用freopen的方法来解决这些错误。 to redirect to dev / null:

Use freopen to redirect to dev/null:

freopen("/dev/null", "w", stderr);

这篇关于是否可以在C ++中禁用stderr?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆