I am wondering why capturing (piping) stdout results in an empty file, while not capturing it results in normal output. I don't get an encoding error when outputting to terminal. Only when piping the output.
Does the encoding change when outputting to a pipe instead of the terminal? Maybe the terminal can signal supported encodings, while a pipe defaults to ASCII?
Piping the output
$ curl -s 'https://www.sunwind.no/Outlet/' | html2text | wc
Traceback (most recent call last):
File "<string>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe5' in position 212: ordinal not in range(128)
0 0 0
Not capturing the output
curl -s 'https://www.sunwind.no/Outlet/' | html2text
* [Forsiden](https://www.sunwind.no/)
* [Logg inn](/login/)
* [Registrer meg](https://www.sunwind.no/register/)
[](https://www.sunwind.no
"Klikk her for å gå til forsiden")
[](https://www.sunwind.se
"Klikk her for å gå til Sunwinds svenske side")
[](https://www.sunwind.fi
"Klikk her for å gå til Sunwinds finske side")
[](https://www.sunwind.no/page/?pid=132
"Klikk her for å gå til Sunwinds danske side")
[](https://www.sunwind.no/en/
"Klikk her for å gå til engelsk side")
[ ](https://www.sunwind.no/)

* __ 0 **kr 0,-**
Nylig lagt til i handlevognen
[Gå til handlekurven](https://www.sunwind.no/account/basket/)
[ Sunwind.no](https://www.sunwind.no/)
* Alle produkter __
##### **[KJØKKEN OG GASS](/product/content/show/?cap=7&KJOKKEN-OG-GASS) **
* [__Gasskomfyr](https://www.sunwind.no/product/category/?cap=13)
* [__Innbyggingsovn gass](https://www.sunwind.no/product/category/?cap=14)
* [__Gasstopp](https://www.sunwind.no/product/category/?cap=15)
* [__Gasskjøleskap](https://www.sunwind.no/product/category/?cap=63)
* [__Kjøleskap 12 volt](https://www.sunwind.no/product/category/?cap=148)
* [__Kjøle- og fryseboks](https://www.sunwind.no/product/category/?cap=144)
* [__Kjøkkenvifte](https://www.sunwind.no/product/category/?cap=65)
* [__Tilbehør og turutstyr](https://www.sunwind.no/product/category/?cap=97)
* [__Gassutstyr og monteringsmateriell](https://www.sunwind.no/product/category/?cap=20)
etc
The html2text alias is a one-line python command:
alias html2text='python -c "import sys,html2text;sys.stdout.write(html2text.html2text(sys.stdin.read().decode(\"utf-8\")))"'
This is the first time I have encountered this behaviour. Is my one-liner somehow not handling piped output?
LC_ALLbefore running...unset LC_ALL; curl ...