FAQ
I've been trying to solve this issue I've been having with the windows
console messing up user inputs.

I've created a small app to test this. The app uses fmt.Scanln(&input) to
get the user input and then fmt.Println(input) to return the inputed value.

First, I've noticed that special characters such as áéíàèìç, end up showing
wierd symbols. Then I changed to chcp 65001 and those characters simply do
not print.

If I do, for instance, mkdir Poisé, a "Poisé" dir is created. But if I try
to create it through another Go program I use for tests, it creates a dir
"Pois?" ( The ? is a symbol inside a square, not really a question mark)

I'm using windows 8 and the latest go release.

Thanks in advance

--

Search Discussions

  • Minux at Jan 26, 2013 at 6:56 pm

    On Sun, Jan 27, 2013 at 2:23 AM, Celso Miranda wrote:

    I've been trying to solve this issue I've been having with the windows
    console messing up user inputs.

    I've created a small app to test this. The app uses fmt.Scanln(&input) to
    get the user input and then fmt.Println(input) to return the inputed value.

    First, I've noticed that special characters such as áéíàèìç, end up
    showing wierd symbols. Then I changed to chcp 65001 and those characters
    simply do not print.

    If I do, for instance, mkdir Poisé, a "Poisé" dir is created. But if I try
    to create it through another Go program I use for tests, it creates a dir
    "Pois?" ( The ? is a symbol inside a square, not really a question mark)

    I'm using windows 8 and the latest go release.
    the Go 1.0.3 release doesn't correctly handle non-ASCII character from/to
    console.
    I expect that if you try the problem should be fixed by the latest
    development version,
    however, you will have to install from source by yourself.

    just follow golang.org/doc/install/source and add a "hg up default" step
    after the
    "hg clone" step.
  • Celso Miranda at Jan 27, 2013 at 3:01 am
    I've installed Go from source like you said, but I'm still getting the same
    error.

    Example

    Input: Olá

    Output: Ol´┐¢

    with chcp 65001

    Input: Olá

    Output: Ol


    I've also noted that if I input a setence into a string, only the first
    word is returned. "my name is celso" outputs "my". I don't know if this is
    related or not. :/


    Sábado, 26 de Janeiro de 2013 18:56:33 UTC, minux escreveu:

    On Sun, Jan 27, 2013 at 2:23 AM, Celso Miranda <celsojc...@gmail.com<javascript:>
    wrote:
    I've been trying to solve this issue I've been having with the windows
    console messing up user inputs.

    I've created a small app to test this. The app uses fmt.Scanln(&input) to
    get the user input and then fmt.Println(input) to return the inputed value.

    First, I've noticed that special characters such as áéíàèìç, end up
    showing wierd symbols. Then I changed to chcp 65001 and those characters
    simply do not print.

    If I do, for instance, mkdir Poisé, a "Poisé" dir is created. But if I
    try to create it through another Go program I use for tests, it creates a
    dir "Pois?" ( The ? is a symbol inside a square, not really a question mark)

    I'm using windows 8 and the latest go release.
    the Go 1.0.3 release doesn't correctly handle non-ASCII character from/to
    console.
    I expect that if you try the problem should be fixed by the latest
    development version,
    however, you will have to install from source by yourself.

    just follow golang.org/doc/install/source and add a "hg up default" step
    after the
    "hg clone" step.
    --
  • Andy Balholm at Jan 27, 2013 at 3:18 am

    On Saturday, January 26, 2013 7:00:56 PM UTC-8, Celso Miranda wrote:

    I've also noted that if I input a setence into a string, only the first
    word is returned. "my name is celso" outputs "my". I don't know if this is
    related or not. :/
    fmt.Scanln, like scanf in C, reads space-separated tokens. So when you scan
    a string, you get one word.

    --
  • Bryanturley at Jan 27, 2013 at 3:43 am
    Do you know the windows console does utf8 and not utf16.
    I seem to remember some windows things preferred utf16.
    Also they did that extended ascii thing what language do you have it set to?

    --
  • Bryanturley at Jan 27, 2013 at 4:25 am

    On Saturday, January 26, 2013 9:43:27 PM UTC-6, bryanturley wrote:
    Do you know the windows console does utf8 and not utf16.

    insert an if in there
    Do you know *IF* the windows console does utf8 and not utf16.

    I seem to remember some windows things preferred utf16.
    Also they did that extended ascii thing what language do you have it set
    to?
    --
  • Celso Miranda at Jan 27, 2013 at 5:30 am
    I didn't know that.

    I'll try and find another solution. Thanks.

    Domingo, 27 de Janeiro de 2013 3:18:44 UTC, Andy Balholm escreveu:
    On Saturday, January 26, 2013 7:00:56 PM UTC-8, Celso Miranda wrote:

    I've also noted that if I input a setence into a string, only the first
    word is returned. "my name is celso" outputs "my". I don't know if this is
    related or not. :/
    fmt.Scanln, like scanf in C, reads space-separated tokens. So when you
    scan a string, you get one word.
    --
  • Celso Miranda at Feb 4, 2013 at 11:52 pm
    So I've updated golang to the default branch and built it from source.

    The problem is still there.

    This is the code I'm using:

    package main

    import (
    "bufio"
    "fmt"
    "os"
    )

    func main() {
    fmt.Println("Example")
    print("example: ")
    in := bufio.NewReader(os.Stdin)
    input, err := in.ReadString('\n')
    if err != nil {
    fmt.Println("Error: ", err)
    return
    }
    fmt.Println(input)
    }


    And I still get a square with an "?" inside each time I use a character
    like ã õ á é í...

    I would guess it's a problem with the windows console, but a similar ruby
    program returns the correct characters... :/

    Domingo, 27 de Janeiro de 2013 5:30:21 UTC, Celso Miranda escreveu:
    I didn't know that.

    I'll try and find another solution. Thanks.

    Domingo, 27 de Janeiro de 2013 3:18:44 UTC, Andy Balholm escreveu:
    On Saturday, January 26, 2013 7:00:56 PM UTC-8, Celso Miranda wrote:

    I've also noted that if I input a setence into a string, only the first
    word is returned. "my name is celso" outputs "my". I don't know if this is
    related or not. :/
    fmt.Scanln, like scanf in C, reads space-separated tokens. So when you
    scan a string, you get one word.
    --
    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/groups/opt_out.
  • Brainman at Feb 5, 2013 at 12:06 am

    On Tuesday, 5 February 2013 10:52:03 UTC+11, Celso Miranda wrote:
    The problem is still there.
    Is it possible to provide "self contain" program? For example, program that
    does not do any input?

    I will investigate it then.

    Alex

    --
    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/groups/opt_out.
  • Celso Miranda at Feb 5, 2013 at 12:14 am

    Terça-feira, 5 de Fevereiro de 2013 0:06:30 UTC, brainman escreveu:

    Is it possible to provide "self contain" program? For example, program
    that does not do any input?
    Do you mean a program like:

    func main {
    var string = "ÃãêÊ"
    fmt.println(string)
    }

    The problem is really in the input part I think. Since printing a string
    with those characters doesn't reproduce this.

    Terça-feira, 5 de Fevereiro de 2013 0:06:30 UTC, brainman escreveu:
    On Tuesday, 5 February 2013 10:52:03 UTC+11, Celso Miranda wrote:

    The problem is still there.
    Is it possible to provide "self contain" program? For example, program
    that does not do any input?

    I will investigate it then.

    Alex
    --
    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/groups/opt_out.
  • Brainman at Feb 5, 2013 at 12:22 am

    On Tuesday, 5 February 2013 11:14:19 UTC+11, Celso Miranda wrote:

    The problem is really in the input part I think. ...
    I suspect as much. Could you do a little experiment - put your input data
    in a file, then run you program with stdin redirected to this file. Does
    that fixes your problem?
    Since printing a string with those characters doesn't reproduce this.
    I do not understand. Are you saying that your program works as expected, if
    input is not used and strings are "hard-coded" inside your program?

    Alex

    --
    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/groups/opt_out.
  • Dave Collins at Feb 5, 2013 at 12:27 am

    On Monday, February 4, 2013 6:14:19 PM UTC-6, Celso Miranda wrote:
    Do you mean a program like:

    func main {
    var string = "ÃãêÊ"
    fmt.println(string)
    }

    The problem is really in the input part I think. Since printing a string
    with those characters doesn't reproduce this.
    This does appear to be an issue with the input. Use the posted program in
    addition to the following steps will allow you to reproduce it:

    1) Launch cmd
    2) Enter chcp 65001 (This selects the UTF-8 code page)
    3) Change the font to Lucida Console for the cmd window by right clicking
    the title bar and selecting properties->font (Need to pick a font with
    glyphs for non-latin chars)
    4) Run the program
    5) Copy and paste ã into the input (assuming you are unable to enter the
    character directly)
    6) Observe the program sees it as a premature EOF

    --
    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/groups/opt_out.
  • Brainman at Feb 5, 2013 at 5:12 am

    On Tuesday, 5 February 2013 11:27:35 UTC+11, Dave Collins wrote:

    This does appear to be an issue with the input. ...
    It does indeed: http://code.google.com/p/go/issues/detail?id=4760. Thank
    you for report.

    Alex

    >

    --
    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/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJan 26, '13 at 6:49p
activeFeb 5, '13 at 5:12a
posts13
users6
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase