title: Using Golang's SSH package to act as a server -- how do I write to stdout?
body: <p>I'm using Go's <a href="https://pkg.go.dev/golang.org/x/crypto/ssh" rel="nofollow noreferrer">ssh</a> package to act an as SSH server, and I wanted to write some tests for that code with an SSH client implemented with the same package.</p>
  <p>In the server-side code, I write stdout data to the ssh <a href="https://pkg.go.dev/golang.org/x/crypto/ssh#Channel" rel="nofollow noreferrer">channel</a> using <code>channel.Write()</code> and stderr data using <code>channel.Stderr().Write()</code>, like so:</p>
  <pre class="lang-golang prettyprint-override"><code>// sample of server code
  switch data.Type {
  case &quot;stdout&quot;:
      channel.Write([]byte(&quot;stdout message!&quot;))
  case &quot;stderr&quot;:
      channel.Stderr().Write([]byte(&quot;stderr message!&quot;))
  }
  </code></pre>
  <p>In the client-side code, I read this data like so:</p>
  <pre class="lang-golang prettyprint-override"><code>// sample of client code
  conn, _ := gossh.Dial(&quot;tcp&quot;, &quot;localhost:2222&quot;, config)
  defer conn.Close()
  
  session, _ := conn.NewSession()
  defer session.Close()
  
  stData := make([]byte, 100)
  stderr, _ := session.StderrPipe()
  stderr.Read(b)
  
  stdout, _ := session.StdoutPipe()
  stdoutData := make([]byte, 100)
  stdout.Read(stdoutData)
  </code></pre>
  <p>This works fine when the code is actually running and communicating with a local ssh process. <strong>The problem</strong> is that when I'm the client, my read from the <code>StderrPipe</code> works as expected, but my read from <code>StdoutPipe</code> simply hangs. It appears that calls to <code>channel.Write()</code> send data somewhere other than the <code>StdoutPipe</code>, so my question is simply: where does that data go?</p>