doujiu1447 2017-02-26 22:53
浏览 161
已采纳

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

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条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥20 用socket实现ping遇到的问题
      • ¥15 综合的类,这个类里面里面又有构造方法,重载方法,有继承,有重写,有接口
      • ¥15 电脑重置失败无法开机也进不了修复模式,如何解决?
      • ¥100 px4飞控如何设置平飞模式下飞机固定的仰角
      • ¥15 关于#python#的问题:不可以使用max ,min ,exit ,break 的情况下找出哪一年份出生率最高,以及哪一年份出生率最低
      • ¥15 WPF中使用DoDragDrop程序会崩,"FatalExecutionEngineError"
      • ¥15 C语言 堆排序 数据结构
      • ¥15 ue如何做自然的物体边缘磨损效果材质
      • ¥15 我是在windows环境下通过IIS部署django项目,但是是这样怎么处理呢
      • ¥30 51单片机测量脉冲周期/频率并加以计算、显示