# Re: Can you temporarily turn off STDERR?

**URL:** <https://www.ruby-forum.com/t/re-can-you-temporarily-turn-off-stderr/66515>\
**Category:** Ruby\
**Created:** [August 26, 2006, 1:38pm UTC](https://www.ruby-forum.com/t/re-can-you-temporarily-turn-off-stderr/66515 "2006-08-26T13:38:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [August 26, 2006, 1:38pm UTC](https://www.ruby-forum.com/t/re-can-you-temporarily-turn-off-stderr/66515/1 "2006-08-26T13:38:29Z")

</div>

> IO#reopen to take
> 
> > 
> 
> class IO  
> begin  
> end  
> puts “normal stuff 2”  
> File.open(‘error\_log\_4’, ‘w’) do |log\_file|  
> $stderr.reopen(‘error\_log\_5’, ‘w’) do  
> $stderr.puts “Stuff on error 5”  
> puts “normal stuff 5”  
> raise “This message courtesy of raise”  
> end  
> rescue =\> e  
> puts e  
> end
> 
> end

Awesome. Now, can we break this with threads? Aredridel?

Of course, I wonder if IO#reopen is thread safe anyway, regardless of  
the block. I’ve never seriously tested it.

Regards,

Dan

This communication is the property of Qwest and may contain confidential  
or  
privileged information. Unauthorized use of this communication is  
strictly  
prohibited and may be unlawful. If you have received this communication  
in error, please immediately notify the sender by reply e-mail and  
destroy  
all copies of the communication and any attachments.

---

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [September 4, 2006, 2:46pm UTC](https://www.ruby-forum.com/t/re-can-you-temporarily-turn-off-stderr/66515/2 "2006-09-04T14:46:24Z")

</div>

> Awesome. Now, can we break this with threads? Aredridel?
> 
> Of course, I wonder if IO#reopen is thread safe anyway, regardless of  
> the block. I’ve never seriously tested it.

Well, it’s thread-safe, but it’s process-global. It’d get turned off for  
the duration of the block, regardless of other threads.
