Command output is not redirected to file

I want to execute the following command, which is related to Rational ClearCase. The output of this command should be redirected to the file testout.

Command

rgy_check -vobs > testout

Output

rgy_check.exe: Error: An unregistered region \<region> was found in
VOB tag entry.
rgy_check.exe: Error: An unregistered region \<region> was found in
VOB tag entry.
...

The file testout is created, but somehow the file is empty.

Grep also doesn't work, it still gives the original output

rgy_check -vobs | grep "06a89"

Solution 1:

Those are error messages. The standard is to write normal output to the STDOUT stream, which you can redirect with >, and to write error messages to the STDERR stream which is redirected with 2>.

Without redirecting, both STDOUT and STDERR end up on the terminal without a way for you to tell what's what.

So if you want your error messages to end up in testout redirect them with

rgy_check -vobs 2> testout

However, from your question, I suppose that testout needs to get the normal output. You could do something like:

rgy_check -vobs > testout 2> testerr

If you need to grep the STDERR stream, this is a little trick to do so:

rgy_check -vobs 2>&1 > testout | grep something

This will first redirect STDERR to the same file descriptor as STDOUT, then redirect STDOUT (but not STDERR) to the file testout, then pipe the STDERR output to the grep command.