Reputation: 4953
I need to run the following code from ruby:
system "wget http://example.org/some/large/archive.zip"
When I run this command I see
Redirecting output to ‘wget-log’.
I need to do tail -f wget-log
to see the progress
How can I see wget output in terminal where I run the ruby process?
I've tried
system "wget -O - http://example.org/some/large/archive.zip > dev/null"
but it didn't help
Maybe there are other options to download large archives with ruby and see the progress?
Upvotes: 0
Views: 958
Reputation: 44370
The ruby provide a good built-in libs to make any kind of http things, for example to download file you can use net/http
:
require 'net/http'
require 'uri'
uri = URI(URI.encode("http://example.org/some/large/archive.zip"))
Net::HTTP.start(uri.host,uri.port) do |http|
request = Net::HTTP::Get.new uri.path
http.request request do |response|
open "/tmp/my_large_file.zip", 'w' do |io|
response.read_body do |chunk|
puts "Writing #{chunk.length} bits ..." # see progress
io.write chunk
end
end
end
end
With wget
you unable to catch any kind of http errors in your ruby code.*
With wget
you unable to make auth, basic for example in your ruby code.*
Use Ruby built-in libs, it is very powerfull.
You able but with some buggy code
Upvotes: 0
Reputation: 33470
You could use the Open3 module, which is in the Ruby's standard library.
This grants you access to stdout, stderr, exit codes and a thread to wait for the child process when running another program.
So, having a pwd
command you can do something like:
require 'open3'
stdout, stderr, status = Open3.capture3('pwd')
puts stdout # ~/ current directory
puts stderr # no error
puts status # pid 25522 exit 0
Upvotes: 1