Ubuntu – Redirection Doesn’t Work

bashcommand line

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?

Best Answer

script -c "/path/prog" /path/log.txt

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.

Related Question