IO.popen and wait for command to finish

Discussion in 'Ruby' started by Uros, Apr 14, 2006.

  1. Uros

    Uros Guest

    Hello,

    I have this for loop thats executing

    IO.popen ("mysql database+i < database.sql")

    It seems that the databases don't get populated with all the data,
    since it seems that one mysql loop doesn't finish as the other one
    start. So it seems, bear in mind I'm no expert, just trying to
    trubleshoot the problem.

    When I do a manual mysq < database.sql it works.

    Is there I way to make ruby wait for the command to finish, befor
    continuing to loop?

    br,
    uros
    Uros, Apr 14, 2006
    #1
    1. Advertising

  2. Uros wrote:
    > Hello,
    >
    > I have this for loop thats executing
    >
    > IO.popen ("mysql database+i < database.sql")
    >
    > It seems that the databases don't get populated with all the data,
    > since it seems that one mysql loop doesn't finish as the other one
    > start. So it seems, bear in mind I'm no expert, just trying to
    > trubleshoot the problem.
    >
    > When I do a manual mysq < database.sql it works.
    >
    > Is there I way to make ruby wait for the command to finish, befor
    > continuing to loop?


    I'd just read the IO until the end. You should do that anyway because
    otherwise the process my block

    IO.popen ("mysql database+i < database.sql") do |io|
    io.each_line {}
    end

    Kind regards

    robert
    Robert Klemme, Apr 14, 2006
    #2
    1. Advertising

  3. Uros

    Uros Guest

    Hello Robert,

    thanks for your answer. That did the trick. :)

    br,
    uros
    Uros, Apr 18, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mike
    Replies:
    6
    Views:
    842
    John C. Bollinger
    Aug 9, 2004
  2. Gary J
    Replies:
    19
    Views:
    39,238
    Chris Uppal
    Aug 31, 2004
  3. Replies:
    8
    Views:
    4,527
  4. Christopher Dancy
    Replies:
    4
    Views:
    104
    Roger Pack
    Apr 16, 2010
  5. Zhidian Du
    Replies:
    2
    Views:
    97
    David Efflandt
    Feb 21, 2004
Loading...

Share This Page