X-Recipient: archive-cygwin AT delorie DOT com X-Original-To: cygwin AT cygwin DOT com Delivered-To: cygwin AT cygwin DOT com DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 697A7385AE5F Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=nifty.ne.jp Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=nifty.ne.jp DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-05.nifty.com 25EAlqN5001841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.ne.jp; s=dec2015msa; t=1655203672; bh=cquaJOBn6bDYFiLDul7piWdZcwx7H76SVYD9+a+MC1Q=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=caGQcndz/Lzo8DAjWz/0K9LjmUJtlR3knygfpdUmy8KF/T42CSMorXPkC/FTGHIKY RwHzUq/+Zd4mQbV8sxordMzsmIOQMg1e0TjqkZ1DgUnwvUOPv4DvvVygLek8V9ZmaX AGrIlzNtktxKKRRzu2VyZNkpVzQCRYJ0s6uSaEqXZNZTL86+rwI1EGvno5LcRX7BQm YYyVK3s/WTi//7o1GhlBj1i3TxHCWRGbNEjyYhtIfcZSsSqXJxzXlFHFpf7c3zhI4k XD5f+CwF8Vph66W2kAqRf3U5yM4Btjj/DaObx8yROOMQv7xhUGO6CsaP6yI5M4G+qh y+l+RcJ+h8RwA== X-Nifty-SrcIP: [119.150.44.95] Date: Tue, 14 Jun 2022 19:47:53 +0900 From: Takashi Yano To: cygwin AT cygwin DOT com Subject: Re: "cat" breaks ANSI codes on Windows Terminal when piping stdout to python or golang Message-Id: <20220614194753.e06a3ff4e6be224249956e50@nifty.ne.jp> In-Reply-To: <1qctAGvnk1sjfU-ob9Y_DTSQIMpPGIn6lDmSoU0JKGPa_EDZkIMYP65gYufkeEVyPX0WCmJDQAJAmGf13IpPPHUmmchN17WDX4PyRxt2omE=@protonmail.com> References: <1qctAGvnk1sjfU-ob9Y_DTSQIMpPGIn6lDmSoU0JKGPa_EDZkIMYP65gYufkeEVyPX0WCmJDQAJAmGf13IpPPHUmmchN17WDX4PyRxt2omE=@protonmail.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32) Mime-Version: 1.0 X-Spam-Status: No, score=-5.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: cygwin AT cygwin DOT com X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Cygwin discussions and problem reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="iso-2022-jp" Content-Transfer-Encoding: 7bit Errors-To: cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com Sender: "Cygwin" On Tue, 14 Jun 2022 08:01:45 +0000 5990 via Cygwin wrote: > ## Bug: > Piping the standard output of cat into the standard input of golang or python, makes the Windows Terminal render ANSI codes as arrows. > > For example: > `\033[36m` turns into `←[36m` (or in base64'd UNICODE: `4oaQWzM2bQ==`) > > ## Environment: > - cat v8.26 > - Windows Terminal v1.12.10982.0 > - golang version go1.17.2 windows/amd64 > - python v3.7.7 > > colors.go > ``` > package main > > import "fmt" > > const colorReset = "\033[0m" > const colorCyan = "\033[36m" > > func main(){ > fmt.Print(string(colorCyan) + "golang-test" + string(colorReset) + "\n") > } > ``` > > > color.py > ``` > from lolpython import lol_py > > lol_py("python-test") > ``` > > > domains.txt is an empty file (from my testing, the contents of domains.txt do not affect this bug) > > ## What works: > The following commands will successfuly output in cyan color > `go run color.go` > `go build color.go && color.exe` > `go build color.go && cat domains.txt | color.exe` > `go build color.go && echo a | color.exe` > `go build color.go && type domains.txt | color.exe` > `py -3.7 color.py` > > ## What triggers the bug: > `cat domains.txt | go run color.go` > OUTPUT: `←[36mgolang-test←[0m` > > `cat domains.txt | py -3.7 color.py` > OUTPUT: `←[38;2;128;237;18mp←[0m←[38;2;139;231;12my←[0m←[38;2;150;225;8mt←[0m←[38;2;161;217;5mh←[0m←[38;2;172;209;2mo←[0m←[38;2;182;200;1mn←[0m←[38;2;192;190;1m-←[0m←[38;2;201;180;1mt←[0m←[38;2;210;170;3me←[0m←[38;2;218;159;5ms←[0m←[38;2;226;148;9mt←[0m` > > Strangely enough, golang compiled executables work perfectly, but piping `cat domains.txt | go run color.go` does not work. > The workaround I had to go with is to use Windows's built-in `type` command instead of `cat`. This was a tricky bug to track-down so I hope this report helps hahah I cannot reproduce your problem. My environment is: cygwin 3.3.5 cat 8.32 Windows Terminal 1.13.11431.0 go version go1.18.3 windows/amd64 What shell did you use? cygwin bash? cmd.exe? powershell? -- Takashi Yano -- Problem reports: https://cygwin.com/problems.html FAQ: https://cygwin.com/faq/ Documentation: https://cygwin.com/docs.html Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple