小编Fos*_*owl的帖子

当输入来自重定向时,为什么 bufio.NewReader 不能正常工作?

我目前正在尝试在网站 CodeChef 上解决这个挑战,当手动输入输入时,我得到了问题中所述的问题的预期答案。

但是当我尝试使用cat in.txt | go run my_program.go我的程序的输出时是不同的。

正如您所看到的,我尝试使用调试fmt.Printf,看起来像是bufio.NewReader随机错过了管道的输入。

我想知道我做错了什么,以及是否有其他方法可以在 Golang 中读取包含多个积分器的整行。

谢谢你帮助我!

内容in.txt

4
3
1 2 3
3
3 2 1
3
0 0 0
3
1 3 2
Run Code Online (Sandbox Code Playgroud)

手动输入输入时的正常输出:

1 1
3 3
1 1
1 2
Run Code Online (Sandbox Code Playgroud)

使用输入文本时输出带有调试消息 cat in.txt | go run my_program.go

debug <1 2 3
>
1 1
debug <>
1 1
debug <>
1 1
debug <>
1 1
Run Code Online (Sandbox Code Playgroud)

我的程序:


package main …
Run Code Online (Sandbox Code Playgroud)

shell input pipe go

-3
推荐指数
1
解决办法
36
查看次数

标签 统计

go ×1

input ×1

pipe ×1

shell ×1