[Eventmachine-talk] How to keep a pipe open

Duane Johnson
2007-11-28T14:56:28Z

Here''s some more information.  The following is a complete listing of
my test app:

> require ''rubygems''
> require ''eventmachine''
> require ''fileutils''
>
> class TexInstance < EventMachine::Connection
>   def receive_data(data)
>     print data
>   end
> end
>
> class GlueServer < EventMachine::Connection
>   def initialize(data)
>     puts "New connection: #{@client_id} #{data.inspect}"
>     super(data)
>   end
>
>   def receive_data(command)
>     # command = command.chomp
>     print "send: #{command}"
>     $instance.send_data command
>   end
> end
>
>
> EventMachine::run do
>   $instance = EventMachine::popen("tex", TexInstance)
>   EventMachine::start_server "127.0.0.1", 4100, GlueServer
> end


Before I can telnet in to port 4100 to have commands forwarded to the
TexInstance / tex command, I receive the EOF error message (in TeX''s
peculiar terminology, "! End of file on the terminal... why?").

Now take a look at this:

> IO.popen("ftp", "r+") do |io|
>   while true do
>     puts io.read(1)
>     #io.puts "test"
>   end
> end

The above simple ruby program behaves as I expect it to: TeX does NOT
receive an EOF from the ruby program, and just waits for input.
What''s going on here?  What''s the difference between
ruby''s popen and
EM''s popen?

Thanks,
Duane Johnson