delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2022/06/14/04:02:25

X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F03EC383DBB2
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1655193743;
bh=P5MKVutc996JI6lErjCS3W92+br5DxcNuLhj/GKU3rk=;
h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post:
List-Help:List-Subscribe:From:Reply-To:From;
b=fp4fRXRfBSREmUf3TMTnHCjXbtEbE6/ctnnvwn9FhpSwPQKVMoiYiFATDdTcDNlgT
ir6rFJkopWtF6lY2UC+4lxN8uCzPC4ruVNuAI7A/PVWaaUyaayPOdtTjmt7T6EFrhK
pnJw5Pe5BiLS2WwIhsZNRy0fXCbfqbqk8XPp3rcg=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8A6073856DF7
Date: Tue, 14 Jun 2022 08:01:45 +0000
To: "cygwin AT cygwin DOT com" <cygwin AT cygwin DOT com>
Subject: "cat" breaks ANSI codes on Windows Terminal when piping stdout to
python or golang
Message-ID: <1qctAGvnk1sjfU-ob9Y_DTSQIMpPGIn6lDmSoU0JKGPa_EDZkIMYP65gYufkeEVyPX0WCmJDQAJAmGf13IpPPHUmmchN17WDX4PyRxt2omE=@protonmail.com>
Feedback-ID: 11940174:user:proton
MIME-Version: 1.0
X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00, DKIM_SIGNED,
DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT,
FREEMAIL_FROM, FREEMAIL_REPLYTO_END_DIGIT, SPF_HELO_PASS, SPF_PASS, TXREP,
T_SCC_BODY_TEXT_LINE autolearn=no 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
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
From: 5990 via Cygwin <cygwin AT cygwin DOT com>
Reply-To: 5990 <5990 AT protonmail DOT com>
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com>
X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 25E82PlF018526

## 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

- ItsIgnacioPortal

-- 
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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright 2019   by DJ Delorie     Updated Jul 2019