Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to redirect persistently stderr to /dev/tty12 so error messages do not touch my nerves when doing something in tty1.

The redirection should go through init.d or ~/.bashrc or ~./bash_profile. Just once.

Can it be done and how?

share|improve this question
add comment

2 Answers

Seems like a really bad idea, and I doubt that the system provides a way to do it.

Whenever a process is created, the calling process determines where its stdin, stdout, and stderr will be directed. There would have to be a general way to override that -- and it would break any mechanisms that redirect stderr explicitly.

For example, if you type:

some_command >some_command.out 2>some_command.err

should some_command's stderr go to some_command.err, or to /dev/tty12?

The closest thing I can think of is to invoke a shell with its stderr redirected:

bash -l 2>/dev/tty12

In my (brief) experiments (redirecting to a file rather than to a tty), this causes the shell to be non-interactive. Adding -i forces it to be interactive -- but the shell prompt is apparently printed to stderr.

Of course you can redirect stderr for individual commands (assuming you're not using csh or tcsh):

some_command 2>some_command.err

and you could define a shell function that does this for you:

e() { "$@" 2>/dev/tty12 ; }

Then, for each command whose stderr you want redirected, just prepend e to the command:

e some_command
share|improve this answer
add comment

Many shells write their interactive prompts to stderr, so you are likely to have trouble interacting with a shell if you redirect it's stderr to /dev/tty12. Also, error messages are important. Why ignore them?

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.