Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Danger of IO duplicate
# This illustrates how IO duplicates flush separately.
# The danger is that this can result in disordered
# output. Run this from the command line:
#
# % ruby io_duplicate_danger.rb
# 1
# 2
# 3
#
# You get what you expect. Now try with redirection:
#
# % ruby io_duplicate_danger.rb &> output.txt
# % cat output.txt
# 2
# 1
# 3
#
a = $stdout
b = a.dup
a.puts 1
b.puts 2
a.puts 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.