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 6361201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:44:46+00:00 2026-05-24T23:44:46+00:00

Given that I wish to test non-blocking reads from a long command, I created

  • 0

Given that I wish to test non-blocking reads from a long command, I created the following script, saved it as long, made it executable with chmod 755, and placed it in my path (saved as ~/bin/long where ~/bin is in my path).

I am on a *nix variant with ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.0.0] compiled with RVM defaults. I do not use Windows, and am therefore unsure if the test script will work for you if you do.

#!/usr/bin/env ruby

3.times do
  STDOUT.puts 'message on stdout'
  STDERR.puts 'message on stderr'
  sleep 1
end

Why does long_err produce each STDERR message as it is printed by “long”

def long_err( bash_cmd = 'long', maxlen = 4096)
  stdin, stdout, stderr = Open3.popen3(bash_cmd)
  begin
    begin
      puts 'err -> ' + stderr.read_nonblock(maxlen)
    end while true
  rescue IO::WaitReadable
    IO.select([stderr])
    retry
  rescue EOFError
    puts 'EOF'
  end
end

while long_out remains blocked until all STDOUT messages are printed?

def long_out( bash_cmd = 'long', maxlen = 4096)
  stdin, stdout, stderr = Open3.popen3(bash_cmd)
  begin
    begin
      puts 'out -> ' + stdout.read_nonblock(maxlen)
    end while true
  rescue IO::WaitReadable
    IO.select([stdout])
    retry
  rescue EOFError
    puts 'EOF'
  end
end

I assume you will require 'open3' before testing either function.

Why is IO::WaitReadable being raised differently for STDOUT than STDERR?

Workarounds using other ways to start subprocesses also appreciated if you have them.

  • 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-24T23:44:46+00:00Added an answer on May 24, 2026 at 11:44 pm

    In most OS’s STDOUT is buffered while STDERR is not. What popen3 does is basically open a pipe between the exeutable you launch and Ruby.

    Any output that is in buffered mode is not sent through this pipe until either:

    1. The buffer is filled (thereby forcing a flush).
    2. The sending application exits (EOF is reached, forcing a flush).
    3. The stream is explicitly flushed.

    The reason STDERR is not buffered is that it’s usually considered important for error messages to appear instantly, rather than go for for efficiency through buffering.

    So, knowing this, you can emulate STDERR behaviour with STDOUT like this:

    #!/usr/bin/env ruby
    
    3.times do
      STDOUT.puts 'message on stdout'
      STDOUT.flush 
      STDERR.puts 'message on stderr'
      sleep 1
    end
    

    and you will see the difference.

    You might also want to check “Understanding Ruby and OS I/O buffering“.

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

Sidebar

Related Questions

Imagine I wish to create (or overwrite) the following file :- C:\Temp\Bar\Foo\Test.txt Using the
Given that you have found a process that you wish to execute a function
Assuming I have the following I wish to unit test: class Foo: IAMethods, IBMethods
I wish to find cells (as a Range) that contain a given text. Is
I wish to create a trigger that would PREVENT any deletion on a given
Given that indexing is so important as your data set increases in size, can
Given that Chrome and Safari use webkit has anyone yet found anything that renders
Given that a function a_method has been defined like def a_method(arg1, arg2): pass Starting
Given that I only have one monitor, what's the best way to debug a
Given that Decimal.MaxValue = 79228162514264337593543950335m Why does the next line give me 7922816251426433759354395034M in

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.