Redirecting stdout to a file not working

I have a script that uses subprocesses to extract 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 the output to a file, I get nothing as a result:

 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 conclusion empty? If it does not contain the same things that were printed in standard output in the first case?

+4
source share
4 answers

I had QApplication as part of a script. It seems like it somehow affects the output redirection. Other scripts without QApplication seem to be redirected as expected. It might be a bug somewhere, but I can't bother tracking it.

0
source

use &> to redirect, this should redirect stdout and stderr to the specified file

+12
source

You sent stdout to a file, but your program reports errors that go to stderr. To set up stderr redirection, use 2> syntax.

This link can help: http://www.tldp.org/LDP/abs/html/io-redirection.html

+1
source

Your output will be stderror. Try redirecting both stderror and stdout using the following:

 <command> 2>&1 <file> 
+1
source

Source: https://habr.com/ru/post/1447129/


All Articles