[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Thread popen and broken pipe problem

L.

9/15/2008 10:58:00 AM

Hello there, I try to execute a list of command in a thread thanks to
popen.
But during command execution user may wants to interrupt / kill the
execution process.
My code looks like that :

@thread = Thread.new do
@command_list.each {|name, cmd|
IO.popen(cmd){ |@pipe|
pipe.each_line {|l|
puts l
}
}
}
end

But when i try to @thread.kill I have a broken pipe error message on
the current command execution.

How to correctly finish and kill the thread without having such
errors?

thanks.
1 Answer

L.

9/15/2008 9:01:00 PM

0

Found it,
when io is set after popen use, it's easy to get the process ID and
then to correctly kill it during its execution.


#get the process id

IO.popen(cmd){ |pipe|
current_process = pipe.id # Saving the PID
pipe.each_line {|l|
puts l
}

#kill the process

Process.kill("KILL", current_process)

et voila.