Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1029053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:28:56+00:00 2026-05-16T12:28:56+00:00

pipe = IO.popen(my_cmd 2>&0) while ??? line = pipe.gets puts line if some_condition end

  • 0
pipe = IO.popen("my_cmd 2>&0")
while ???
  line = pipe.gets
  puts line if some_condition
end

This is using Ruby 1.8.7 on Windows. my_cmd is an application that prints database records to the stdout. One line per database record, and there’s no way to know how many records there will be before I run the command. Each gets call returns one record. Each gets call could take a while, too. It’s going over a network to a very large database, so the gets call won’t be instant.

I’m processing the input just fine. The problem is, the loop never ends.

my_cmd terminates when it reaches the end of the database. How does my Ruby script know when my_cmd is done? What should ??? be in the code I posted above?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T12:28:57+00:00Added an answer on May 16, 2026 at 12:28 pm

    Either

      while !out.eof?
    

    or when you

     Process.wait pipe.pid
    

    http://en.wikibooks.org/wiki/Ruby_Programming/Running_Multiple_Processes

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I write this: from subprocessing import Popen, STDOUT, PIPE p = Popen([myproc], stderr=STDOUT,
Given this : import os import subprocess def check_server(): cl = subprocess.Popen([nmap,10.7.1.71], stdout=subprocess.PIPE) result
How can I pipe between two separate console application running in different console windows?
i've got this snazzy python code: import subprocess value = subprocess.Popen([php,./php/php_runner.php],stdout=subprocess.PIPE); the problem is,
I try to pipe the output from a command line command through Ruby. It
popen() alternative - I am using the accepted answer (pipe/fork/exec method) to solve my
I'm using Windows 7, and I've tried this under Python 2.6.6 and Python 3.2.
I'm using IO.popen(cmd) in my Ruby script to run an Ironruby subroutine. In my
I wan to create a pipe between 3 commands: cat = subprocess.Popen(cat /etc/passwd, stdout=subprocess.PIPE)
import os import subprocess proc = subprocess.Popen(['ls','*.bc'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) out,err = proc.communicate() print out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.