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

  • Home
  • SEARCH
  • 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 7663279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:01:06+00:00 2026-05-31T14:01:06+00:00

In my Ruby script, I call on a Perl script and wait for it

  • 0

In my Ruby script, I call on a Perl script and wait for it to finish executing. However, there are times that the Perl script encounters a series of errors and I would like Ruby to be able to handle these errors automatically. So, I implemented the following…

begin
    IO.popen(cmdLineExecution) do |stream|
          stream.each do |line|
              puts line
              if line =~ /Some line that I know is an error/
                 raise MyOwnException
              end 
          end
    end

    begin
          #Wait on the child process
          Process.waitpid 
    rescue Errno::ECHILD
    end
rescue MyOwnException
   #Abort the command mid processing, and handle the error
end

However, the Perl script continues to execute even though an exception has been thrown, only that it is not piping the output to STDOUT anymore. At this point, if I want to stop the Perl process, I have to go into the Task Manager and manually stop it. Then Process.waitpid ends and continues from there. It is either that or I stop Ruby and the Perl process continues to run in the background and I still have to manually stop it.

BTW: This is on Windows

So thus the question is how do I stop IO.popen without the Perl process from becoming a orphan process mid process?

  • 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-31T14:01:07+00:00Added an answer on May 31, 2026 at 2:01 pm

    So – disclaimer, I am using Ruby 1.8.6 and on Windows. It is the only Ruby that the software I use currently supports, so there may be a more elegant solution. Overall, it came down to making sure the process died using the Process.kill command before continuing execution.

    IO.popen(cmdLineExecution) do |stream|
      stream.each do |line|                         
          puts line
          begin
            #if it finds an error, throws an exception
            analyzeLine(line) 
          rescue correctionException 
            #if it was able to handle the error 
            puts "Handled the exception successfully"
            Process.kill("KILL", stream.pid) #stop the system process
          rescue correctionFailedException => failedEx
            #not able to handle the error
            puts "Failed handling the exception"
            Process.kill("KILL", stream.pid) #stop the system process
            raise "Was unable to make a known correction to the running enviorment: #{failedEx.message}"
          end
      end
    end
    

    I made both the exceptions standard classes that inherit Exception.

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

Sidebar

Related Questions

I would like to call a Ruby script when a user uploads an image
In ruby, is it possible to specify to call another ruby script using the
I have a Ruby script that generates a UTF8 CSV file remotely in a
I have a Ruby script in my Rails app that I use to load
I'm writing a Ruby script and would like to use a n-ary tree data
so i have ruby script that simply writes to a test.txt file with hello
I have a ruby script that does a few perforce operations (through the scripting
I am trying to write a Ruby script in one file. I would like
Scenario: I have to call an external program from my Ruby script, and this
Today, I tried to call a script from ruby. I did like this: `./aaa.sh`,

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.