execute python script in python and redirect output code example Example: redirect python output to file $ python foo.py > file