Open3

M

Matt Do

Hello everyone. I have created a sales system for my company. Basically
you telnet to the system and enter your login name, password ... From
there you can access the sales system.

I am working on a feature to write reports for a certain area of the
system. For this, I want it to just shell out to VIM (Vi iMproved). For
this I will be using Popen3, so the telnet user can access the sytem.

This is some example code I have ...

def runVimForReport( node_number, file_name )
stdin, stdout, stderr = Open3.popen3('vim #{file_name}' )

read_thread = Thread.new { start_read(stdout,stderr) }
write_thread = Thread.new { start_write(stdin,stderr) }

write_thread.join
read_thread.join
end

def start_read( stdout , stderr )
loop do
the_input = stdout.getc
nodeSendData( @node_number, the_input.chr )
STDOUT.flush
end

puts("EXIT READ THREAD")
end

def start_write( stdin , stderr )
loop do
STDOUT.flush
input = nodeGetChar( @node_number )
stdin.putc(input)
end
end

This code works well, the user can access VIM just fine. There is only
one problem ...

When the user exits the program it continues to read/write to the
process. It doesn't just simply exit the functions. How do I tell when a
program has exited? I tried other programs and all are the same ... It
just hangs. The user has to logout and log back in. Even when
disconnecting the telnet session, the program is still running in the
background.

Is there a variable I can check in my loop to see if the program has
exited?

Thanks for all your help!

- Matt
 
M

Matt Do

Got it fixed. It wasn't that the program wasn't exiting it was that the
ruby program. I added this to my start_read thread.

if the_input == nil
Thread.kill(@write_thread)
break
end
 

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,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top