Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to put my program's output into a file. I keyed in the following :

./prog > log 2>&1

But there is nothing in the file "log". I am using the Ubuntu 11.10 and the default shell is bash.

Anybody know the cause of this AND how I can debug this?

share|improve this question
Are you sure the prog produce any output? – enzotib Nov 4 '11 at 5:47
@enzotib: Yes. It does. In fact I am using the gnu scientific lib. It also prints out stuff. When I comment out the line which calls the library function, redirection works fine though. Any idea now? – Rich Nov 4 '11 at 19:47
script -c "/path/prog" /path/log.txt
share|improve this answer
Sometimes shell redirecting does not work (specifically - when one shell spawns another shell, I think:). Above is the generic solution that simply grabs all the shell output and places it into the file. In your case this should work as well, since you're expecting output on stdout/stderr. – Andrejs Cainikovs Dec 7 '11 at 20:31

this worked here, when the ./prog 2>&1 >log.txt alone, would not work properly:

./prog 2>&1 |cat >log.txt
share|improve this answer

Your Answer


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.