Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

2 Answers 2

script -c "/path/prog" /path/log.txt
share|improve this answer
1  
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

 
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.