3

I'm writing a ruby script that calls apt-get. I would like to log/display all the output from the apt-get command.

Backticks, %x and the rest mostly return the final output (if at all). I've also looked at IO.popen and Open3.popen series, but they stop logging after the first message.

Is there a way to dump all output as it happens from the shell command?

1 Answer 1

2

You can use IO::popen for this:

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

Hope this helps

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

1 Comment

popen3 also allows capturing the STDERR channel.

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.