Closing files opened with Open3.popen

Discussion in 'Ruby' started by Francis Hwang, Jun 2, 2004.

  1. Is there anyway to close a file that I opened with Open3.popen ? I'm
    running a lot of external process (and capturing their stderr), but if
    the process runs too long eventually I get a "Too many open files"
    error.

    Francis
     
    Francis Hwang, Jun 2, 2004
    #1
    1. Advertisements

  2. Francis Hwang

    Ara.T.Howard Guest

    not sure i understand but:

    ~ > ruby -r open3 -e 'ios = Open3::popen3 "sh"; system "ps"; ios.map{|io| io.close}; system "ps"'

    PID TTY TIME CMD
    5379 pts/5 00:00:00 bash
    6681 pts/5 00:00:00 ruby
    6683 pts/5 00:00:00 sh
    6684 pts/5 00:00:00 ps

    PID TTY TIME CMD
    5379 pts/5 00:00:00 bash
    6681 pts/5 00:00:00 ruby
    6685 pts/5 00:00:00 ps


    -a
    --
    ===============================================================================
    | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
    | PHONE :: 303.497.6469
    | A flower falls, even though we love it; and a weed grows, even though we do
    | not love it. --Dogen
    ===============================================================================
     
    Ara.T.Howard, Jun 2, 2004
    #2
    1. Advertisements

  3. Francis Hwang

    Paul Brannan Guest

    Use IO#close.

    Paul
     
    Paul Brannan, Jun 2, 2004
    #3
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.