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

homebrew, ruby

Solution

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.

Problem

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?

Original source