The Go Programming Language: example ch1/dup2 console vs file behavior

Hi people,

New to Go and studying The Go Programming Language book, example chapter 1, dup2. I create a test file, test.txt with the following content:

harry
ron
hermione
ron
hagrid
dumbledore
harry
sneep
hermione

Running main.exe test.txt yields the expected output:

2       harry
2       ron
2       hermione

Running main.exe, entering the above content via the keyboard and ending with ctrl+c, typically misses one entry (not the same during several runs). Possible output:

2       ron
2       hermione

and

2       harry
2       ron

Is this expected behavior? (I’m working on Windows 10, installed go1.11.4.)

Help appreciated.

Hi. Could you show us the program?

The first chapter of GOPL is available online: http://www.gopl.io/ch1.pdf

The code for dup2 is printed on pages 10f.

1 Like

For me, if I run that program from the book linked here and Ctrl-C it, then I do see no further output at all. The program is just cancelled, and to be honest, I’d expect the same on windows.

If though I use Ctrl-D which is on linux used to send EOF, then I see the correct output every time.

As far as I remember, the windows equivalent of Ctrl-D is Ctrl-Z.

1 Like

Hi Norbert,

This:

answered my question, thanks!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.