<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def init_log_file(self):
 """ redirects stdout to a log file to prevent printing to a hanging terminal when dealing with the compiled binary. """

        # redirect terminal output
        self.old_stdout = sys.stdout
        sys.stdout = open(os.path.join(self.WD, "demag_gui.log"), 'w+')