Repository: go
Issue: fmt: cannot read more than 254 characters in Windows when calling Fscanln
Labels: OS-Windows,NeedsInvestigation

<!--
Please answer these questions before submitting your issue. Thanks!
For questions please use one of our forums: https://github.com/golang/go/wiki/Questions
-->

### What version of Go are you using (`go version`)?

<pre>
$ go version
go version go1.15.4 darwin/amd64
$ gotip version
go version devel +b34b0aaf69 Thu Nov 12 15:28:43 2020 +0000 darwin/amd64
</pre>

### Does this issue reproduce with the latest release?

Yes. It also reproduces with current tip `go version devel +b34b0aaf69 Thu Nov 12 15:28:43 2020 +0000 darwin/amd64`

### What operating system and processor architecture are you using (`go env`)?

<details><summary><code>go env</code> Output</summary><br><pre>
$ go env
N/A
</pre></details>

### What did you do?

```go
package main

import (
	"fmt"
	"os"
)

func main() {
	var s string
	_, err := fmt.Fscanln(os.Stdin, &s)
	if err != nil {
		panic(err)
	}

	fmt.Println(s)
}
```

```console
$ GOOS=windows go build -o reproducer_stdin.exe main.go
$ GOOS=windows gotip build -o reproducer_stdin_tip.exe main.go
```

### What did you expect to see?

On the Windows host, I type `A` character 257 times after running the program, then press enter key. The Go program reads them correctly.

```console
PS C:\Users\mig\Downloads> .\reproducer_stdin_tip.exe | Measure-Object -char | Select-Object -expand Characters
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
257
PS C:\Users\mig\Downloads> .\reproducer_stdin.exe | Measure-Object -char | Select-Object -expand Characters
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
257
```

### What did you see instead?

On the Windows host, I typed `A` character 257 times after running the program, then presed enter key. The Go program stdin froze after 254 characters.

```console
PS C:\Users\mig\Downloads> .\reproducer_stdin_tip.exe | Measure-Object -char | Select-Object -expand Characters
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
254
PS C:\Users\mig\Downloads> .\reproducer_stdin.exe | Measure-Object -char | Select-Object -expand Characters
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
254
````

> **NOTE**: this seems to also be borken when copying&pasting text.

> Note: this was tested using a `Windows (Windows Server 2012 R2 Datacenter)` Azure machine with default settings and environment. Just downloaded the cross-compiled binaries into it and ran them.
> Edit: This is also reproducible using Windows Command Prompt using an Azure `Windows (Windows 10 Pro)` default machine.

---

I don't really know if this is related to Go at all or an issue with Powershell itself, but I thought it was worth submitting an issue. This was initially discovered by @karelorigin.


Best regards,
Miguel