FAQ
Control-D is recognized anywhere on the line. Its meaning is to terminate
the pending read and return whatever characters have already been typed. If
you type

abc^D

the pending read will get "abc". That's all control-D does, but a
consequence is that if you type it at the beginning of the line, the
pending read will get "", a zero-length read, which may be interpreted (but
isn't really) end of file.

It's been like this for over 45 years on Unix. I can't speak for Windows,
though.

-rob

On Sat, Mar 5, 2016 at 3:59 AM, John McKown wrote:
On Fri, Mar 4, 2016 at 10:39 AM, wrote:

I asked this question in stackoverflow.com
<http://stackoverflow.com/questions/35754563/golang-how-to-terminate-the-bufio-scan-from-terminal/35759721#35759721>.
The Scan() function doesn't catch Ctrl + Z in Windows 7 terminal.

If I type some lines of text from console, it catches the Ctrl + Z
successfully.

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\prj\goproj>copy con test.txt
abc
^Z
1 file(s) copied.

C:\prj\goproj>

Does the Scan() function suppose to catch Ctrl + Z ? If so, is it a bug?
​I don't _do_ Windows <grin/>. But the Linux does the same thing with
Ctrl-D (Linux end-of-file from a terminal). But it is not just Go which has
this problem. I duplicated it in a simple BASH shell script using the
"read" command. Apparently a ^D on Linux is _only_ recognized if it is at
the logical "start of line" location. And it is recognized immediately. I
would guess this is the same in Windows. And it appears, to me, to be an
artifact of the operating system's control of the keyboard (i.e. only
recognize ^Z as end-of-input if it is the only thing on a line). ​


Thanks.

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
A fail-safe circuit will destroy others. -- Klipstein

Maranatha! <><
John McKown

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 3 of 4 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMar 4, '16 at 4:39p
activeMar 4, '16 at 10:40p
posts4
users4
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase