title: Pipe out both stdin and stdout os.exec Golang
body: <p>I'm trying to run a command in golang, feeding a reader to its stdin, returning its stdout, then converting its stderr to an error message.</p>
  <p>My problem is this: my code works just fine when only piping into stdin and returning stdout. However, when I also try to load stderr into a buffer, the command will hang if stdout has more information than stdin. I've tested this and it even applies if a stdout is one single byte bigger than stdin. I've been stuck on this for hours and can't haven't been able to find any solutions on the internet.</p>
  <p>Here's the relevant code:</p>
  <pre><code>var b bytes.Buffer
  
  cmd := exec.Command(convCmd, convArgs...)
  
  stdin, _  := cmd.StdinPipe()
  stdout, _ := cmd.StdoutPipe()
  cmd.Stderr = &amp;b
  
  go func() {
      defer stdin.Close()
      io.Copy(stdin, inStream)
  }()
  
  err = cmd.Start()
  
  if b.String == &quot;&quot; {
      err = nil
  } else {
      err = errors.New(b.String()
  }
  
  return stdout, err
  </code></pre>
  <p>This issue is driving me nuts, my only guess is that the command is waiting for stdin to equal the size as stdout, but it seems so bizarre that it only does it when I attempt to load stderr into a buffer.</p>