docker api ContainerExecInspect无法获取正确的退出代码

I am using docker engine-api(github.com/docker/engine-api) to execute some command

I use client.ContainerExecCreate and then client.ContainerExecInspect to run my command and then get the command exit code(I run multiple commands in the same container so the exit code get from ContainerInspect is useless for me.)

This is my function use to execute command in container

http://pastebin.com/rTNVuv9T

but ContainerExecInspect return wrong values sometime, because sometimes ContainerExecInspect is called before the command exit and it said exit code is zero, which is wrong

And I wrote a testcase to test it

http://pastebin.com/PED1Rf4k

And the result will not be 233, it will be 0

I have set ExecConfig.Detach = true and ExecStartCheck.Detach = true, but no helps

Is there any way to wait until the command exit then get the exit code?

Addition:

For some of my command running is shell script not a executable, so I think I need to prefix /bin/bash, and wait the container exit, is not what I want, I want to wait the command exit, and the container is still running

I think now I can solve my problem

The main point is when using containerExecAttach it will exposed the hijacked connection and, I can judge whether the command exit by read from the connection until EOF

There are a few point to set then

  1. Should set ExecConfig AttachStdout to true
  2. Then read from hijacked conn

Here is a sample code

atinfo, err := cli.ContainerExecAttach(ctx, execID, ec)

// error handling

defer atinfo.Close()
c = atinfo.Conn 

one := make([]byte, 1)
_, err = c.Read(one)

if err == io.EOF {
    println("Connection closed")
}

This will wait until the command execute complete

ExecConfig is set to

ec.Detach = false
ec.Tty = false
ec.AttachStdout = true