diff --git a/src/tox/action.py b/src/tox/action.py index e7f9b77bb..2215e4968 100644 --- a/src/tox/action.py +++ b/src/tox/action.py @@ -1,5 +1,6 @@ from __future__ import absolute_import, unicode_literals +import locale import os import pipes import signal @@ -125,7 +126,17 @@ def popen( exit_code = process.returncode finally: if out_path is not None and out_path.exists(): - lines = out_path.read_text("UTF-8").split("\n") + # Output of Python sub-processes like `python -m + # virtualenv` may use some other system-dependent + # encoding when redirected to a file. Let's try + # UTF-8 (the common case) and fall back to the + # system encoding if that fails. + try: + encoding = "UTF-8" + lines = out_path.read_text(encoding).split("\n") + except UnicodeDecodeError: + encoding = locale.getpreferredencoding(False) + lines = out_path.read_text(encoding).split("\n") # first three lines are the action, cwd, and cmd - remove it output = "\n".join(lines[3:]) try: