diff --git a/invoke/runners.py b/invoke/runners.py index e77463c5c..389767474 100644 --- a/invoke/runners.py +++ b/invoke/runners.py @@ -239,7 +239,11 @@ def get(): yield data for data in codecs.iterdecode(get(), encoding, errors='replace'): if not hide: - dst.write(data) + # Make sure no UnicodeError happens, even if the data is + # garbled (e.g. due to encoding mismatch with the child). + encoded_data = data.encode(dst.encoding, errors='replace') + clean_data = encoded_data.decode(dst.encoding) + dst.write(clean_data) dst.flush() cap.append(data)