5

I'm trying to redirect error output to both a file and the terminal and throw away standard output, but I can't figure it out. Does anybody know how to do it?

0

2 Answers 2

14
myCommand 2>&1  1>/dev/null | tee /path/to/some/file.txt

STDOUT gets black-holed into /dev/null

STDERR gets redirected to STDOUT

tee receives STDOUT and re-echoes it as well as writing it to file

Sign up to request clarification or add additional context in comments.

3 Comments

I was close :) I had this command and it didn't work myCommand 1>/dev/null 2>&1 | tee /path/to/some/file.txt. Your solution works. Thank you
I tried your solution first then remembered they should be the other way around ;)
The order matters because the redirections are interpreted from left to right. Hence the first redirection sets sets stderr to the same stream as stdout. Then the second one switches stdout away.
0

See this post. You will need to use the tee command to direct in multiple directions.

http://www.linuxforums.org/forum/programming-scripting/163161-redirecting-stdout-file-terminal-stderr-file.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.