I have a program that's running a separate thread, which contains three execfile() statements running external Python scripts. Without changing these scripts, is there a way to have the print() statements within them print their commands out to a log file? From my code below, I need the print commands from within File1, File2, and File3 to go into a log file, without being able to change those files. Is this possible?
Code:
MyThread.py
import threading
class MyThread(threading.Thread):
    def run(self):
        execfile('File1.py')
        execfile('File2.py')
        execfile('File3.py')
Program.py
from MyThread import *
MyThread().start()
I've seen the Q/A posted here (redirect prints to log file) and tried this solution, but the print() statements from the external files aren't added to the log file:
import threading, sys
class MyThread(threading.Thread):
    def run(self):
        old_stdout = sys.stdout
        output_file = open('output.log', 'w')
        sys.stdout = output_file
        execfile('File1.py')
        execfile('File2.py')
        execfile('File3.py')
        sys.stdout = old_stdout
        output_file.close()