重定向标准输出 [英] redirect stdout
问题描述
如果我使用freopen(afile,w,stdout)重定向stdout;
然后我使用fclose(stdout)关闭stdout,基本上我只是
关闭" afile" ;.
我必须重新建立stdout最初指向的内容?
谢谢
If I redirect stdout by using freopen("afile", "w", stdout);
and then I closed stdout using, fclose(stdout), essentially I am just
closing "afile".
I have to reestablish what stdout originally pointed to?
thanks
推荐答案
Michael Gaab写道:
Michael Gaab wrote:
如果我使用freopen(afile,w重定向stdout ;,stdout);
然后我关闭stdout使用,fclose(stdout),基本上我只是关闭afile。
我必须重新建立什么stdout最初指向?
If I redirect stdout by using freopen("afile", "w", stdout);
and then I closed stdout using, fclose(stdout), essentially I am just
closing "afile".
I have to reestablish what stdout originally pointed to?
嗯,我不知道这是否有用但是...
FILE * save_stdout = stdout;
stdout = fopen(" xyz"," w");
..
..
..
close(stdout);
stdout = save_stdout;
NR
Hmmm, I don''t know if this would work but...
FILE *save_stdout = stdout;
stdout = fopen("xyz", "w");
..
..
..
close(stdout);
stdout = save_stdout;
NR
在文章< vr ************ @ corp.supernews.com>,
Noah Roberts< nr * *****@dontemailme.com>写道:
In article <vr************@corp.supernews.com>,
Noah Roberts <nr******@dontemailme.com> wrote:
Michael Gaab写道:
Michael Gaab wrote:
如果我使用freopen(afile,w,stdout)重定向stdout;
然后我关闭stdout使用,fclose(stdout),基本上我只是关闭afile。
我必须重新建立stdout最初指向的内容?
If I redirect stdout by using freopen("afile", "w", stdout);
and then I closed stdout using, fclose(stdout), essentially I am just
closing "afile".
I have to reestablish what stdout originally pointed to?
<嗯,我不知道这是否可行但是...
Hmmm, I don''t know if this would work but...
[制作stdout指针的备份副本并重新分配]
有时,但不便携,如果我没有弄错的话; stdout需要
扩展为FILE *类型的表达式,但该表达式不需要
是一个可修改的左值,我似乎记得有关
目前的实施情况,这不是最后一次出现。
dave
-
Dave Vandervies dj******@csclub.uwaterloo.ca
我以为每个人都疯了。这就是我前来参观的原因,所以
我会有宾至如归的感觉。
- 在comp.lang.c中杀死Wahler
[making a backup copy of the stdout pointer and reassigning it]
Sometimes, but not portably, if I''m not mistaken; stdout needs to
expand to an expression of type FILE *, but that expression need not
be a modifiable lvalue, and I seem to recall reports of sightings of
current implementations where it isn''t one last time this came up.
dave
--
Dave Vandervies dj******@csclub.uwaterloo.ca
I thought everyone here was insane. That''s why I come to visit, so
I''ll feel at home.
--Mike Wahler in comp.lang.c
" Noah Roberts" < NR ****** @ dontemailme.com>在消息中写道
news:vr ************ @ corp.supernews.com ...
"Noah Roberts" <nr******@dontemailme.com> wrote in message
news:vr************@corp.supernews.com...
Michael Gaab写道:$ b $嗯,我不知道这是否有用但是......
FILE * save_stdout = stdout;
stdout = fopen(" xyz"," w");
Michael Gaab wrote: Hmmm, I don''t know if this would work but...
FILE *save_stdout = stdout;
stdout = fopen("xyz", "w");
这篇关于重定向标准输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!