FAQ
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?

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.

Search Discussions

  • John McKown at Mar 4, 2016 at 4:59 pm

    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.
  • Rob Pike at Mar 4, 2016 at 9:30 pm
    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.
  • Tapio Raevaara at Mar 4, 2016 at 10:40 pm

    On Friday, March 4, 2016 at 6:40:06 PM UTC+2, amk...@gmail.com 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?

    Thanks.
    The way I understand it is that the Windows console only has any special
    handling for Ctrl+C and Ctrl+Break, see MSDN(1).

    Ctrl+Z never sends an EOF, it sends the ASCII "substitute character" 0x1a,
    which was traditionally used to indicate the end of a character stream on
    DOS. It's every program's own responsibility to recognize it *when reading
    data from console*.

    Which is nasty.

    (1):
    https://msdn.microsoft.com/en-us/library/windows/desktop/ms682541%28v=vs.85%29.aspx

    --
    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.

Related Discussions

Discussion Navigation
viewthread | post
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 © 2021 Grokbase