Re: Temporarily close stdout?
- From: richard@xxxxxxxxxxxxxxx (Richard Tobin)
- Date: 30 Apr 2008 13:07:05 GMT
In article <64f07b4c-2742-45a0-bbc3-38c9f2c67c29@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Joakim Hove <joakim.hove@xxxxxxxxx> wrote:
/* Temporarily close stdout: */
fclose(stdout);
job_nr = lsb_submit( &request , &reply );
/* Reopen stdout */
stdout = fdopen(1 , "a");
I don't think there's any standard C way to to what you want.
It looks as if you're using something Posix-like. The fclose(stdout)
will have closed the underlying file descriptor (1), so your fdopen()
doesn't work. As someone else said, you could use dup() to keep a
copy of it. But standard C doesn't let you assign to stdout; I'm not
sure whether Posix does. I have a vague recollection of some systems
providing fdreopen(), but it doesn't seem to be standard. You could
fdopen() a new FILE *, and use that instead of stdout in your code,
or if you have /dev/fd you could use freopen() on /dev/fd/N, where N
is what you got back from dup().
But closing stdout is dubious in the first place. Are you sure the
library won't complain about stdout being closed? It would be better
to freopen() stdout to /dev/null.
-- Richard
--
:wq
.
- Follow-Ups:
- Re: Temporarily close stdout?
- From: Joakim Hove
- Re: Temporarily close stdout?
- References:
- Temporarily close stdout?
- From: Joakim Hove
- Temporarily close stdout?
- Prev by Date: Re: Temporarily close stdout?
- Next by Date: Re: Is cast operator unary or binary? How many operands?
- Previous by thread: Re: Temporarily close stdout?
- Next by thread: Re: Temporarily close stdout?
- Index(es):
Relevant Pages
|