go-dexec
                                
                                 go-dexec copied to clipboard
                                
                                    go-dexec copied to clipboard
                            
                            
                            
                        Missing output from fast-running commands
I wanna run sh -c "echo $(pwd)".
cmd is executed by dexec, but it doesn't output anything.
cmd2 is executed by go's built-in exec , it works.
package main
import (
  "log"
  "github.com/ahmetalpbalkan/dexec"
  "github.com/fsouza/go-dockerclient"
  "os/exec"
)
func main() {
  cl, _ := docker.NewClient("unix:///var/run/docker.sock")
  d := dexec.Docker{cl}
  m, _ := dexec.ByCreatingContainer(docker.CreateContainerOptions{
    Config: &docker.Config{Image: "busybox"}})
  cmd := d.Command(m, "sh", "-c", "echo $(pwd)")
  b, err := cmd.Output()
  if err != nil {
    log.Fatal(err)
  }
  log.Printf("%s", b)
  cmd2 := exec.Command("sh", "-c", "echo $(pwd)")
  bb, err := cmd2.Output()
  if err != nil {
    log.Fatal(err)
  }
  log.Printf("%s", bb) 
}
@waitingkuo ah that's nasty. That sounds a bit like the known issue we got at https://godoc.org/github.com/ahmetalpbalkan/go-dexec#hdr-Known_issues
- You may receive empty stdout/stderr from commands if the executed command does not end with a trailing new line or has a different flushing behavior.
Can you try appending an empty line echo after that? (echo $(pwd);echo)
@ahmetalpbalkan it's still the same. Sometimes it can output correctly, sometimes empty.
@waitingkuo yep that flakiness actually is my experience with running fast commands as well while I developed this. It appears like there is either a flushing bug in the go-dockerclient's hijack protocol implementation I am using or in the docker engine. (Former is more likely.)
When you run slower commands (or add sleeps it is actually working fine). What I can suggest is, try using https://godoc.org/github.com/fsouza/go-dockerclient directly (you can take a look at dexec source code and see how we call into that library) and repro it with the go-dockerclient only, and open an issue on its repository.
That would fix the downstream.
@fsouza any ideas? Have you heard of any missing output cases from go-dockerclient attach/hijack functionality?
@ahmetalpbalkan I haven't, but I can help debugging it. I'll try to reproduce it using only go-dockerclient.