# Silencing Standard Error

**URL:** <https://www.ruby-forum.com/t/silencing-standard-error/191276>\
**Category:** Ruby\
**Created:** [July 8, 2010, 6:45pm UTC](https://www.ruby-forum.com/t/silencing-standard-error/191276 "2010-07-08T18:45:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![crucoba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e8c25b/32.png) [@crucoba](https://www.ruby-forum.com/u/crucoba)\
**Post date:** [July 8, 2010, 6:45pm UTC](https://www.ruby-forum.com/t/silencing-standard-error/191276/1 "2010-07-08T18:45:38Z")

</div>

Hello,

I am new here, so I apologize if this is a lame question. I have googled  
for quite awhile trying to find out the answer to my question to no  
avail.

In a script, I am issuing this line:

```
returnAddress = `defaults read

```

/path/to/conappsqa.bundle/serverconfig serverAddress`

Which reads a plist entry on my computer. If the plist entry is not  
present then I get the following spew on the command line when I run the  
script:

2010-07-08 09:32:37.273 defaults[29326:40b]  
The domain/default pair of (/path/to/conappsqa.bundle/serverconfig,  
serverAddress) does not exist

Is there a way I can eliminate this kind of spew? I just want to execute  
the code and handle the error. I don’t want all the mess.

Any tips?

Thanks.

---

<div class="post-metadata">

**Author:** ![crucoba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e8c25b/32.png) [@crucoba](https://www.ruby-forum.com/u/crucoba)\
**Post date:** [July 8, 2010, 9:34pm UTC](https://www.ruby-forum.com/t/silencing-standard-error/191276/2 "2010-07-08T21:34:02Z")

</div>

Have you tried just simply stderr? You could either run the script and  
have 2\>/dev/null be the redirect, or inside the backticks I think you  
can safely use the same redirect.

You can do it more ruby specific by redefining $STDERR, but that’s  
probably overkill if it’s a simple script.

James

---

<div class="post-metadata">

**Author:** ![crucoba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e8c25b/32.png) [@crucoba](https://www.ruby-forum.com/u/crucoba)\
**Post date:** [July 8, 2010, 9:35pm UTC](https://www.ruby-forum.com/t/silencing-standard-error/191276/3 "2010-07-08T21:35:01Z")

</div>

David C. wrote:

> Any tips?

If you’re running under some Unix-like O/S, then try

returnAddress = `defaults read /path/to/conappsqa.bundle/serverconfig serverAddress 2>/dev/null`

Otherwise look at open3.rb in the standard library.

---

<div class="post-metadata">

**Author:** ![crucoba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e8c25b/32.png) [@crucoba](https://www.ruby-forum.com/u/crucoba)\
**Post date:** [July 13, 2010, 10:47am UTC](https://www.ruby-forum.com/t/silencing-standard-error/191276/4 "2010-07-13T10:47:05Z")

</div>

2010/7/8 David C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> returnAddress = `defaults read
> 
> Is there a way I can eliminate this kind of spew? I just want to execute  
> the code and handle the error. I don’t want all the mess.
> 
> Any tips?

If you want to silence all error output and you run on some form of  
\*nix you can do:

$stderr.reopen ‘/dev/null’

Example:

$ ruby19 -e ‘x=`sh -c "echo foo >&2"`’  
foo  
$ ruby19 -e ‘$stderr.reopen(“/dev/null”);x=`sh -c "echo foo >&2"`’  
$

Otherwise you need open3 as Brian said or do the fork exec yourself.

Kind regards

robert
