How to get continuous output of subprocess started using backtick in ruby
-
21-08-2019 - |
Question
I have a ruby application that executes ant as a subprocess using backtick. This works without any problems. When I do puts ant
, ruby waits for the subprocess, ant, to finish completely and then prints the output to stdout. How do I get ruby to print the output from the subprocess continuously?
Solution
You could use IO.popen
.
IO.popen("ant") do |output|
while line = output.gets do
# ... maybe puts line? something more interesting?
end
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow