Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I (or how can I) save the output of brew doctor with pipes?

Tags:

homebrew

ruby

I'm not sure just how specific this is, but when I run 'brew doctor' I see some error messages. If I want to save those messages I run brew doctor > brewErrors.txt. I see the errors in my terminal but if I cat brewErrors.txt I just get a file with a few inlines. Is this a more general issue (say of Ruby or some kind of library/method of reporting) or a super narrow one? And for the future, if I ever encounter this how can I work around/fix this?

like image 242
Boris Avatar asked Jan 30 '14 15:01

Boris


1 Answers

The problem is that > redirects STDOUT and generally error messages appear on STDERR. Every unix process has 3 file descriptors open by default: STDIN, STDOUT and STDERR. You're redirecting STDOUT but should be redirecting either just STDERR with

brew doctor 2> brewErrors.txt

or both STDERR and STDOUT with

brew doctor &> brewErrors.txt

This is the same whether you're using a bash shell or the newer zsh shell.

like image 159
Fred the Magic Wonder Dog Avatar answered Oct 21 '22 07:10

Fred the Magic Wonder Dog