Python stdout logging: terminal vs bash file
Question: I am not expert in Bash and Python, so this question might appear silly.

I have a Python script called `learn.py` and I noticed two different
behaviours of the standard output, when redirected to a log file.

If I call this from terminal, I can see the log file size growing while the
script is running.

    
    
    $ ./learn.py > file.log
    

However, if I create a bash file for the same purpose:

    
    
    #!/bin/bash
    ./learn.py > file.log
    

the script starts (I checked with `pgrep`) but it does not seem to run, as the
log file stays empty. Am I missing something?


Answer: I solved using the [Logging facility for
Python](https://docs.python.org/2/howto/logging.html), by inserting

    
    
    import logging
    logging.basicConfig(filename='file.log',level=logging.INFO)
    

and replacing every occurrence of `print "..."` with

    
    
    logging.info("...")
    

The final Bash script:

    
    
    #!/bin/bash
    ./learn.py
    

