0
ドッカーのライブラリが提供するcontainerAttach()関数を使用して出力を取得するために、ドッカーコンテナに接続するアプリケーションがあります。 その関数は、bufio.Readerへのポインタを持つHijackedResponse構造体を返します。golang - ioを使用している奇妙な文字bufio.ReaderからSTDOUTにコピーするコピー
私は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.
私はこれらの行のそれぞれの最初の文字から来ている見当がつかない。どんな助けでも大歓迎です。必要ならば私はドッカーコンテナの周りの詳細を提供することができます&私は自分のコードで使用していますが、私は彼らが読者を介して出力を得ているので、彼らはうまくいると仮定しています。
行は行の残りのバイト数を含むバイトが付いている指定する必要がありました。 io.Copy関数とos.Stdoutは、これらのバイトを追加する何もしません。 –
@CeriseLimónに感謝しますが、私の出力にそのバイトが表示されないようにすっきりした方法を提案していますか? – Anton