I want to be able to pass the output of a child process in Ruby
eg.
p `ping google.com`
I want to see ping answers immediately; I do not want to wait for the process to complete.
You should use IO # popen :
IO.popen("ping -c 3 google.com") do |data| while line = data.gets puts line end end
Instead of using backlinks, you can do the following:
IO.popen('ping google.com') do |io| io.each { |s| print s } end
Hurrah!
If you want to capture both stdout and stderr , you can use popen2e :
stdout
stderr
popen2e
require 'open3' Open3.popen2e('do something') do |_stdin, stdout_err, _wait_thr| stdout_err.each { |line| puts line } end
Source: https://habr.com/ru/post/905128/More articles:Do not let comparevalidator display error before clicking button - c #local user name is forbidden - c #Why is the degree symbol different from UTF-8 from unicode? - unicodesetInterval () only function works once - javascriptPass this object inside the constructor to setIntervall - javascriptHow to play audio file in Android? - androidHow do you clear the ArrayAdapter? - androidI have a memory leak using ListActivity in Android - androidSome annoying warnings that still allow the application to work, but would like to remove - iosJPA map with entity key and entity value - javaAll Articles