title: Reading from stdin in golang
body: <p>I'm trying to read from Stdin in Golang as I'm trying to implement a driver for Erlang. I have the following code:</p>
  
  <pre><code>package main
  
  import (
      "fmt"
      "os"
      "bufio"
      "time"
  )
  
  func main() {
      go func() { 
          stdout := bufio.NewWriter(os.Stdin) 
          p := []byte{121,100,125,'\n'}
          stdout.Write(p)
          }()
      stdin := bufio.NewReader(os.Stdin)
      values := make([]byte,4,4)
      for{
          fmt.Println("b")
          if read_exact(stdin) &gt; 0 {
              stdin.Read(values)
              fmt.Println("a")
              give_func_write(values)
          }else{
              continue
          }
      }
  }
  
  
  
  
  func read_exact(r *bufio.Reader) int {
      bits := make([]byte,3,3)
      a,_ := r.Read(bits)
      if a &gt; 0 {
          r.Reset(r)
          return 1
      }
      return -1
  }
  
  func give_func_write(a []byte) bool {
      fmt.Println("Yahu")
      return true
  }
  </code></pre>
  
  <p>However it seems that the <code>give_func_write</code> is never reached. I tried to start a goroutine to write to standard input after 2 seconds to test this.</p>
  
  <p>What am I missing here?
  Also the line <code>r.Reset(r)</code>. Is this valid in go? What I tried to achieve is simply restart the reading from the beginning of the file. Is there a better way?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>After having played around I was able to find that the code is stuck at <code>a,_ := r.Read(bits)</code> in the <code>read_exact</code> function</p>