On Sun, Dec 12, 2021 at 5:15 PM Денис Мухортов
<muhortovdeni...@gmail.com> wrote:

> It's a little unclear how os.stdin actually works. Why, if you just run the 
> program, is data from stdin constantly being listened to?
> For example:
> func main() {
>     sc := bufio.NewScanner(os.Stdin)
>     for sc.Scan() {
>         txt := sc.Text()
>         fmt.Printf("echo: %s\n", txt)
>     }
> } But if you send it to stdin ahead of time, the loop will run once and the 
> program will exit(echo smth | go run main.go)

There's no difference in those two cases, just try to press ctrl-D in
the terminal. IOW, in both cases the loop loops until stdin reports
EOF.

>From https://pkg.go.dev/bufio#Scanner

""""
Scanning stops unrecoverably at EOF, the first I/O error, or a token
too large to fit in the buffer.
""""

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAA40n-VFSgk%3DnLtyyMNevH%2BYcj3G8F-vHEjZkVr88iiDUig5Vg%40mail.gmail.com.

Reply via email to