Redirection of stdout to a file not working

mpenkov picture mpenkov · Nov 20, 2012 · Viewed 20k times · Source

I have a script that uses subprocesses to fetch HTML:

misha@misha-K42Jr:~/git/domain_classifier$ python webkit_retrieve.py error-cut.txt html/error -N 5
http://kurabo.co.jp HostNotFoundError
http://monarch.com HostNotFoundError
http://nssmgmt.com HostNotFoundError
http://sbcglobal.net HostNotFoundError
http://dynamixcorp.com SslHandshakeFailedError
http://groupe-synox.com RemoteHostClosedError
QFont::setPixelSize: Pixel size <= 0 (0)
http://www.cnn.com NoError
http://pacbell.net TimeoutError

If I run the same script, but redirect output to a file, I get nothing in the output:

misha@misha-K42Jr:~/git/domain_classifier$ python webkit_retrieve.py error-cut.txt html/error -N 5 > stdout.txt
QFont::setPixelSize: Pixel size <= 0 (0)
misha@misha-K42Jr:~/git/domain_classifier$ cat stdout.txt
misha@misha-K42Jr:~/git/domain_classifier$

Why is the output empty? Should it not contain the same things that were printed to stdout in the first case?

Answer

Saddam Abu Ghaida picture Saddam Abu Ghaida · Nov 20, 2012

use &> for redirection, this should redirect stdout and stderr to designated file