ç的popen不会赶上标准错误 [英] c popen won't catch stderr
本文介绍了ç的popen不会赶上标准错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图用的popen()
搭上调用的标准错误,当然,它似乎并没有被这样做。任何想法?
I'm trying to use popen()
to catch the stderr of a call, but of course it doesn't seem to be doing that. Any ideas?
我的code看起来或多或少是这样的:
My code looks more or less like this:
popen("nedit", "r");
但我发现了这一切垃圾关于非UTF8我的屏幕上......
But I'm getting all this garbage about non-utf8 on my screen...
推荐答案
的popen
为您提供了一个进程的标准输出,而不是它的标准错误的文件句柄。它的第一个参数是PTED作为一个shell命令间$ P $,所以你可以在里面做重定向:
popen
gives you a file handle on a process' stdout, not its stderr. Its first argument is interpreted as a shell command, so you can do redirections in it:
FILE *p = popen("prog 2>&1", "r");
或者,如果你不想在标准输出的,
or, if you don't want the stdout at all,
FILE *p = popen("prog 2>&1 >/dev/null", "r");
(除了任何其他文件的/ dev / null的
是可以接受的为好。)
这篇关于ç的popen不会赶上标准错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文