英文:
golang - weird characters using io.Copy to copy from bufio.Reader to 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容器和附加选项的更多详细信息,尽管我认为它们是正确的,因为我通过读取器获取了输出。
英文:
I have an application that attaches to a docker container to get its output using the containerAttach() function provided by the docker library.
That function returns a HijackedResponse struct with a pointer to a bufio.Reader.
I'm trying to stream text from the bufio.Reader to stdout and getting unexpected characters in the strings written to stdout.
The code:
_, err := io.Copy(os.Stdout, hijackedResponse.Reader)
Expected output:
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.
Actual output:
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.
I have no idea where the first character in each of those lines has come from. Any help would be much appreciated. If needed I can provide more details around the docker container & attach options I'm using in my code although I'm assuming they're fine as I'm getting the output via the reader.
答案1
得分: 2
我发现问题了 - 我的 containerConfig 需要指定 Tty: true
。
英文:
I found the problem - my containerConfig needed to specify Tty: true
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论