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

标签 go docker io stdout

我有一个应用程序附加到 docker 容器以使用 containerAttach() 获取其输出docker库提供的功能。 该函数返回 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 容器和附加选项的更多详细信息,尽管我假设它们没问题,因为我正在通过阅读器获取输出。

最佳答案

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

关于golang - 使用 io.Copy 将奇怪的字符从 bufio.Reader 复制到 STDOUT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42475239/

相关文章:

tomcat - 在go中解析tomcat日志文件的时间戳

spring-boot - 当在Dockers上部署时,Spring Cloud Config Server在URL -http://localhost:8888上提供了Connect Timeout Exception

haskell - 在 if 内执行 readLine

linux - linux中的api和设备文件有什么区别?

amazon-web-services - 在 Kubernetes 上还是直接在 EC2 实例上部署 Docker 应用程序?

c - MPI IO读写 block 循环矩阵

go - 如何从多值返回函数访问单个值?

go - 为什么 golang 允许命名 slice 类型赋值而无需显式类型转换?

go - Google表格API-下载无格式的数据

docker - 在docker-compose中无法使用其名称作为主机调用另一个容器