我的意思是编写C / C ++代码,以便能够向程序的用户指定如何将各种消息类别(每个消息类别以我应该知道的文件描述符编号输出)重定向到不同的用户选择文件。例如:3:来自轻微警告的消息,4:来自数字例程(而非类型3)的消息,等等。
这带来了很多问题,我问了一些相关的问题(在底部列出)。 即使所有问题都没有得到答案,但根据所发表的评论,我最终还是很困惑。特别是,我总结了一个具体的基本问题(这就是为什么这不是骗子的原因):
可以编写使用手工提取的文件描述符编号的C / C ++代码吗? 那就像
int main() {
const int fd = 3;
and then writing to fd
with either
ssize_t nbytes = write(fd, ...
要么
FILE * fp = fdopen(fd, "a"); /* or some other mode */
fprintf(fp, ...
(并且可能还有其他方法)。
In Smart-write to arbitrary file descriptor from C/C++, I posted code that included this usage, and comments posted suggested a way of completing code (even though I did not manage to make it work).
In any case, it would be ok to use a hand picked fd
number.
In Safety check prior to using fdopen, comments posted suggested I shouldn't ever use a hand picked fd
number.
然后,我对此感到困惑。
My third related question is Correct way of using fdopen