title: Ruby popen3 - How to prevent that repeatedly writing to stdin results in a timeout?
body: <p>Currently I'm writing to stdin in a loop when stdout provides me with the last line marker "EE\n". Now it should go on until the loop is terminated but for some reason stdout is not providing any new lines at iteration 625 and so on, I think the problem is with stdin not listening or capturing the new puts.</p>
  
  <p>I've tried to do it with PTY.spawn instead of Open3.popen3 but no luck there. Also I've set a timeout in expect and when this occurs to write again to stdin. I got the idea to keep stdin open from this post:
  <a href="https://stackoverflow.com/questions/22851698/ruby-popen3-how-to-repeatedly-write-to-stdin-read-stdout-without-re-opening">ruby popen3 -- how to repeatedly write to stdin &amp; read stdout without re-opening process?</a></p>
  
  <p>I need to keep stdin open because the next step will be that stdout is providing the new information for stdin and so on.</p>
  
  <pre><code>def testen()
      Open3.popen3("./pos.tx") do |stdin, stdout, stderr, wait_thr|
          stdin.sync = true
          stdout.sync = true
          stdin.puts "e0"
          count = 0
          while true
              stdout.expect("\n") do |result| 
                  if result[0] == "EE\n"
                      # sleep(0.1)
                      count +=1
                      print count.to_s+"\n"
                      stdin.puts "e0"
                  end
              end
          end
          stdin.close
  
          # status = wait_thr.value
          stdout_str = stdout.read
          print stdout_str
      end
  
  end
  
  testen
  </code></pre>
  
  <p>So this piece of code results in a final print of 625 which means there where 625 successful <code>stdin.puts "e0"</code>. But it should go on and on, until some user interference like <code>ctrl c</code>.</p>
  
  <p><strong>Solution</strong></p>
  
  <p>I was not reading from stderr which resulted a full pipe, now I use popen2.</p>