How to read from standard input in the console?

后端 未结 11 1149
迷失自我
迷失自我 2020-11-28 00:54

I would like to read standard input from the command line, but my attempts have ended with the program exiting before I\'m prompted for input. I\'m looking for the equivalen

11条回答
  •  無奈伤痛
    2020-11-28 01:26

    I'm late to the party. But how about one liner:

    data, err := ioutil.ReadAll(os.Stdin)
    

    and press ctrl+d (EOT) once input is entered on command line.

提交回复
热议问题