title: Why the encoding of text is different when using io.Copy in go language?
body: <p>I am trying to rebuild a tee-like util by go language on Windows. 
  But I found the encoding of the output is not always the same. </p>
  
  <p>To make the problem simple, I wrote this program:</p>
  
  <pre><code>package main
  
  import (
      "fmt"
      "io"
      "os"
  )
  
  func main() {
      count, err := io.Copy(os.Stdout, os.Stdin)
      fmt.Println(count, err)
  }
  </code></pre>
  
  <p>I named it test. 
  In the Windows command console, I got these output:</p>
  
  <pre><code>&gt;test
  中
  中
  5 &lt;nil&gt;
  </code></pre>
  
  <p>It works fine with no pipe and redirect.</p>
  
  <pre><code>&gt;echo 中 | test
  ��
  5 &lt;nil&gt;
  </code></pre>
  
  <p>The output is collapsed if I get stdin from a pipe. </p>
  
  <pre><code>&gt;echo 中 | test &gt; test.txt
  
  &gt;type test.txt
  中
  5 &lt;nil&gt;
  </code></pre>
  
  <p>It works again when I redirect the output to a file.</p>
  
  <pre><code>&gt;test &gt; test.txt
  中
  
  &gt;type test.txt
  荳ｭ
  5 &lt;nil&gt;
  </code></pre>
  
  <p>But not work when I use the normal stdin and redirect to a file. 
  If I open this test.txt here by other editors like notepad++, I found it is encoded in UTF-8 and the content is <code>中</code>. </p>
  
  <p>If I use Cygwin with a UTF-8 encoded console on Windows, everything is just good. </p>
  
  <p>From the output, I know that the number of bytes the program copied is 5, which means it is using UTF-8 in the program no matter what the stdin is. 
  But as I know the windows command line console is basically use non-unicode encoding, why it is converted into UTF-8? And is there a way to let the program just copy what the stdin send without any converting? </p>
  
  <p>btw. If I use tee from gnuWin32 to do the same test, everything just works good. </p>
  
  <pre><code>&gt;where tee
  D:\Tools\gnuWin32\bin\tee.exe
  
  &gt;echo 中 | tee
  中
  
  &gt;tee tee.txt
  中
  中
  ^C
  &gt;type tee.txt
  中
  </code></pre>
  
  <p>Is there anyone know the reason of this and what is the solution? </p>