0

I have numbers.rb

loop do
  puts rand(10)
  sleep(1)
end

I have pipe.rb

ARGF.each_line do |line|
  puts "received #{line}"
end

I'm trying to pipe output of number.rb to pipe.rb. Like this –

ruby lib/numbers.rb | ruby pipe.rb

However, this doesn't do what I want it to do. Basically, the piped input doesn't seem to be recieved until the process number.rb stops executing. But numbers.rb isn't supposed to end. How do I pipe the stdout of numbers.rb continuously, as it happens, to pipe.rb?

1 Answer 1

1

10 seconds after having posted this question, figured the answer out. Have to put $stdout.sync = true at the top of numbers.rb

Sign up to request clarification or add additional context in comments.

1 Comment

Instead of writing what is basically a comment in an answer, improve this by showing a complete working example, then when Stack Overflow lets you you can select it as the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.