0

Let's say I have a command called "enjoy." I'm expecting enjoy to give valid output and an error message. How do I call enjoy such that the valid output goes to one file and the error messages go to another file?

1 Answer 1

4
enjoy > log.txt 2> errors.txt

Assuming of course that you've used STDOUT and STDERR properly and you're using a nice shell. If you're using csh, you need to do something more complicated:

(enjoy > log.txt) >& errors.txt

This works because >& redirects both STDOUT and STDERR - but STDOUT has already been redirected. The parentheses make sure that STDOUT is long gone before the data gets anywhere near the overzealous >&.

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

5 Comments

Assuming you use a sane shell - Bourne, Korn, Bash or any other similar more-or-less POSIX compliant shell. If you use a C Shell derivative, you may have a much harder time managing this.
Here's my command: (RNAsubopt -s < TestSequences.txt > SubOptTestSequences.txt) >& dummy.txt sh: Syntax error: Bad fd number
Which shell are you using? That looks like a Bourne shell error - it was expecting a number after the >&. Typing echo $SHELL may illuminate - but if it says /bin/sh then we may need to look at the to see whether that is really Bourne shell or whether it is a link to bash or some other shell. You tagged unix; which version of Unix are you running on?
Ubuntu 11.10's default shell. I believe it's bash.
Yep that's bash. Try my first example that should work for you.

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.