Pipe call freezes Tk interface . How to unblock?

T

Tony.Makhlouf

Relatively new to Ruby (3 weeks) and Tk (3 days):

I have a ruby script that controls a C++ application via a pipe. I have
a Tk interface on top of it:

require 'tk'
require 'thread'

#setup Tk interface here
Thread.new { Tk.mainloop}; #Tk thread.

pipe=IO.popen("myapp.exe", "r+")

pipe.puts "input text goes here..."

loop do
app_out=pipe.gets #FREEZES Tk interface if lengthy
if (app_out=~/result is/)
puts "app has generated #{app_out}"
end
end


The problem I am facing is that the call to pipe.gets freezes the Tk
interface while waiting for a response from myapp.exe

I would like to find a way to do a non-blocking call to pipe.gets .

One solution I thought of is to launch a second ruby script in a
different process, and have that one talk via a pipe to myapp.exe, and
then communicate with the main script via some other non-blocking
method. Is there an easy way to have 2 Ruby scripts talk to each other,
other than pipes?

PS: must work on Win32 Active State or Cygwin
Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top