Skip to content

Commit

Permalink
Redirect stdout/stderr in child.py
Browse files Browse the repository at this point in the history
  • Loading branch information
yuxuan-ms committed Nov 2, 2023
1 parent 47144a6 commit b9680d4
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions testplan/runners/pools/child.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,14 @@ def _setup_logfiles(self):
"log file = %(file)s (log level = %(lvl)s)",
{"file": log_file, "lvl": self.logger.level},
)
# redirect stdout/stderr
stderr_fd = open(stderr_file, "w")
stdout_fd = open(stdout_file, "w")
os.close(2)
os.close(1)
os.dup2(stderr_fd.fileno(), 2)
os.dup2(stdout_fd.fileno(), 1)

sys.stderr = open(stderr_file, "w")
sys.stdout = open(stdout_file, "w")
fhandler = logging.FileHandler(log_file, encoding="utf-8")

formatter = logging.Formatter(LOGFILE_FORMAT)
Expand Down

0 comments on commit b9680d4

Please sign in to comment.