title: ruby: when copying streams, how to make it pass input characters?
body: <p>To better describe my problem, I have a ruby script which builds an expect script, writes it to a file and calls #exec with the file path:</p>
  
  <pre><code>expect /tmp/expectscript
  </code></pre>
  
  <p>Problem is, I lose control after I call exec, and can't clean that file. I also have credentials, so it's a no go. </p>
  
  <p>I'm now trying to pass the script as a string to stdin, but that's impossible using ruby + exec, so I rewrote it to open3. All went well, until I saw that stuff like tabs and backspace is not properly handled by the streams. Here's a reproduction:</p>
  
  <pre><code>#!/usr/bin/env
  require 'open3'                              
  Open3.popen3("expect -") do |i, o, e, t|     
    Thread.start { IO.copy_stream(o, $stdout) }
    Thread.start { IO.copy_stream(e, $stderr) }
    i &lt;&lt; "spawn bash\ninteract\nwait\nexit\n"  
    Thread.start { IO.copy_stream($stdin, i) } 
    t.value                                    
  end            
  </code></pre>
  
  <p>Now try to run this, write "ls" and press "TAB". or backspace, for that matter. the shell output is not autocompleting. </p>
  
  <p>This seems to be a problem with the copy_stream function, which is maybe handling certain characters before it copies them. Is there something I can do about this? </p>