需要帮助。我有从 docker 容器执行命令的代码。需要正确地从 exec 命令获取标准输出。
execConfig:= types.ExecConfig{Tty:false,AttachStdout:true,AttachStderr:false,Cmd:command}
respIdExecCreate,err := cli.ContainerExecCreate(context.Background(),dockerName,execConfig)
if err != nil {
fmt.Println(err)
}
respId,err:=cli.ContainerExecAttach(context.Background(),respIdExecCreate.ID,types.ExecStartCheck{})
if err != nil {
fmt.Println(err)
}
scanner := bufio.NewScanner(respId.Reader)
for scanner.Scan() {
fmt.Println(output)
}
Run Code Online (Sandbox Code Playgroud)
从输出中我看到了有趣的情况: 来自 gyazo 的屏幕
如何正确删除字节?
我只发送命令 := []string{"echo","-n", "hello word"}