Write all output from shell command

I am writing a ruby โ€‹โ€‹script that calls apt-get

. I would like to record / display all output from a command apt-get

.

Backticks, %x

and the rest mostly return the final result (if at all). I also looked at the IO.popen and Open3.popen series, but they stopped registering after the first post.

Is there a way to dump all the output like it does from a shell command?

+3


source to share


1 answer


You can use IO :: popen for this:

IO.popen("apt-get install foobar") do |apt|
  apt.each do |line|
    puts line
  end
end

      



Hope it helps

+2


source







All Articles