Open robertschweizer opened 2 years ago
I've just stumbled across this problem as well. A workaround that seems to be working for me is to set the newline
parameter on sys.stdout
using the following:
import sys
sys.stdout.reconfigure(newline='')
Looking forward to a fix for this as well. Have been using Invoke tasks in gitlab since longer time now because it's powerful and clean CLIs
Problem
Using example
tasks.py
:I get the following output in CMD (wrapping in Python to see newline characters):
In most applications and terminals (e.g. CMD, Git bash etc.), the double carriage returns are no problem and are just ignored. I only faced issues in Gitlab's CI output: https://gitlab.com/gitlab-org/gitlab/-/issues/342686
Potential Solution
invoke currently uses
os.read()
to read the subprocess' output stream asbytes
and then decodes it tostr
. This string contains\r\n
line endings on Windows.Then, invoke encodes the captured string (on Python 2 only) and prints it using
sys.stdout.write()
, which usesTextIOWrapper
's newline handling. By default, this replaces any found\n
with\r\n
on Windows, ending up with\r\r\n
.To solve this, invoke should probably print the captured
bytes
before decoding, by usingsys.stdout.buffer.write()
, which does not do any newline handling and thus matches theos.read()
used for reading.