Brian Candler wrote:
> Spawn a pty. There's pty.so in the standard library, which is a C 
> extension and unfortunately not well documented, but google for 
> "PTY.spawn" to find some examples, e.g.

Thanks for the suggestion Brian but I don't think that will work for my 
case.  I need to send keystrokes to stdin of the current process itself. 
Maybe there's a way to do that with PTY but I couldn't get it to work.

Here's a quick example that demonstrates the issue:

[code]
# prompt is already up and waiting
t = Thread.new {
   print "Enter command: "
   $stdout.flush

   # get the next command to run from the user
   command = gets

   puts "Executing command #{command}"
}

# want this to enter the desired command as though it
#  was typed by the user himself (show up in stdout but
#  also be picked up by any open 'gets' requests)

# ... ? (send "foo" to stdin of the current process)


t.join

puts "Done."
[/code]

-- 
Posted via http://www.ruby-forum.com/.