golang - 使用 io.Copy 从 bufio.Reader 复制到 STDOUT 的奇怪字符

golang - weird characters using io.Copy to copy from bufio.Reader to STDOUT

我有一个附加到 docker 容器的应用程序,使用 docker 库提供的 containerAttach() 函数获取其输出。 该函数 returns 是一个 HijackedResponse 结构,带有指向 bufio.Reader.

的指针

我正在尝试将文本从 bufio.Reader 流式传输到 stdout,并在写入 stdout 的字符串中获取意外字符。

代码:

_, err := io.Copy(os.Stdout, hijackedResponse.Reader)

预期输出:

Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but
will not be persisted to local or remote state storage.

实际输出:

6Refreshing Terraform state in-memory prior to plan...
=The refreshed state will be used to calculate this plan, but
9will not be persisted to local or remote state storage.

我不知道每行中的第一个字符来自哪里。任何帮助将非常感激。如果需要,我可以提供有关我在代码中使用的 docker 容器和附加选项的更多详细信息,尽管我假设它们很好,因为我通过 reader 获取输出。

我发现了问题 - 我的 containerConfig 需要指定 Tty: true