How to disable stderr temporarily?

How to disable stderr temporarily?

Post by David C » Wed, 21 Aug 1996 04:00:00



Hi!

In my program, I need to temporrarily disable the stderr.
the reason is when I call a purchased library function, it always
dumps a message "Not for Resale" to stderr. I wonder how I can
disable the stderr before I call that function and then enable
it later?

Thanks.

David

 
 
 

How to disable stderr temporarily?

Post by Brian Kravi » Wed, 21 Aug 1996 04:00:00


: Hi!

: In my program, I need to temporrarily disable the stderr.
: the reason is when I call a purchased library function, it always
: dumps a message "Not for Resale" to stderr. I wonder how I can
: disable the stderr before I call that function and then enable
: it later?

        stderr is just a file descriptor that you should just be able
to close just like any other file descriptor.  As far as reopening it
after it's been closed, I'm not sure -- you probably won't be able to,
since it's a constant (and opening it would try to redefine it).

--

[%> "Life is just a candle and your dreams must give it flame" - Neil Peart <%]
[%> "Defer no time, delays have dangerous ends!" - Shakespeare's Henry VI   <%]

 
 
 

How to disable stderr temporarily?

Post by Mario Klebs » Wed, 21 Aug 1996 04:00:00



>Hi!
>In my program, I need to temporrarily disable the stderr.
>the reason is when I call a purchased library function, it always
>dumps a message "Not for Resale" to stderr. I wonder how I can
>disable the stderr before I call that function and then enable
>it later?

What about

        oldStderr=dup(2);
        newStderr=open("/dev/null",O_WRONLY);
        close(2)
        dup2(newStderr,2);
        close(newStderr);
        /* call you library routine here */
        close(2)
        dup2(oldStderr,2);

All error checks are missing.

73, Mario
--

Institut fuer Robotik und Prozessinformatik der TU Braunschweig
Hamburger Strasse 267, 38114 Braunschweig, Germany

 
 
 

How to disable stderr temporarily?

Post by Icarus Spar » Thu, 22 Aug 1996 04:00:00





>: Hi!

>: In my program, I need to temporrarily disable the stderr.
>: the reason is when I call a purchased library function, it always
>: dumps a message "Not for Resale" to stderr. I wonder how I can
>: disable the stderr before I call that function and then enable
>: it later?

>    stderr is just a file descriptor that you should just be able
>to close just like any other file descriptor.  As far as reopening it
>after it's been closed, I'm not sure -- you probably won't be able to,
>since it's a constant (and opening it would try to redefine it).

The correct thing to do here is to use either the 'dup' or 'dup2' system
calls, to make a second copy of file descriptor 2. You can then close
filedescriptor 2, make the call to the library, and then use 'fdopen'
to reestablish the connection.

stderr is NOT a constant, it might be a constant pointer.
Icarus

 
 
 

How to disable stderr temporarily?

Post by Ken Pizzi » Fri, 23 Aug 1996 04:00:00




>    stderr is just a file descriptor that you should just be able
>to close just like any other file descriptor.  As far as reopening it
>after it's been closed, I'm not sure -- you probably won't be able to,
>since it's a constant (and opening it would try to redefine it).

man freopen

                --Ken Pizzini

 
 
 

1. temporarily redirecting stdout/stderr

Step 1 (OK so far):

Step 2:

Ooh, ouch. I'm surprised this worked anywhere... (actually, it works on
HP-UX as well, so maybe it's a by-product of conventional (archaic) libc
implementations).

What you want to do instead of the above second step is to:

   fflush(stdout);
   dup2(outcopy, fileno(stdout));  /* should close stdout.log */
   close(outcopy);

--

HP Performance Delivery Lab (ex-CLL)    +1 (408) 447-2851

2. Question on Linux. I need a little motivation to get it!

3. (off topic) Re: temporarily reassigning stdout/stderr

4. HELP: Installing linux to Syquest EZ135???? Is it possible?

5. Disabling screensaver temporarily

6. Executing programs with GNU C/C++ including paramters ?

7. NOTICE: voting@hut.fi temporarily disabled

8. R.H. 2.1/Newbie Setup/X setup dies/help!

9. Zsh: Temporarily disable history expansion

10. disabling screensaver/DPMS temporarily

11. Temporarily disabling DiskSuite mirroring?

12. Can I disable the 387 temporarily

13. disable a user temporarily