Re: [go-nuts] question about stdin

2021-12-12 Thread Jan Mercl
On Sun, Dec 12, 2021 at 5:15 PM Денис Мухортов 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() { > tx

Re: [go-nuts] question about stdin

2021-12-12 Thread 'Axel Wagner' via golang-nuts
os.Stdin is whatever the file descriptor 0 is being connected to by the OS. Depending on the type of file descriptor, Read will behave differently. If you call a program on the command line, the shell connects it to its controlling terminal, which is usually line-buffered and a read from it will bl

[go-nuts] question about stdin

2021-12-12 Thread Денис Мухортов
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 y