File.popen/IO.popen

Discussion in 'Ruby' started by hariwise@gmail.com, May 20, 2006.

Guest

Hi:
>From ruby code, I am executing another command and reading the output
using File.popen.
The external command might run for a long time and I was to ensure that
if the ruby interpreter is terminated, the process that is executing
the command is cleaned up as well.

Advertisements

wrote:
> Hi:
>
>>From ruby code, I am executing another command and reading the output
> using File.popen.
> The external command might run for a long time and I was to ensure that
> if the ruby interpreter is terminated, the process that is executing
> the command is cleaned up as well.
>
> How do I accomplish this ? I am working in windows.

At least under cygwin this should work: use method #pid of the IO object
created by popen() to record the process id. Then trap SIGINT (or
whatever) and send it via Process.kill to the child process.

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!