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

我有一个应用程序,附加到一个docker容器得到它的输出使用docker库提供的containerAttach()函数。 该函数返回一个带有指向bufio.Reader的指针的HijackedResponse结构体。

我试图将文本从bufio.Readerstream到标准输出,并获取写入标准输出的string中的意外字符。

代码:

_, 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容器和附加选项,虽然我假设他们罚款,因为我通过阅读器得到的输出。

我发现这个问题 – 我的containerConfig需要指定Tty: true