Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby: PIpe URL contents to bash command

Tags:

ruby

pipe

Edit: This just got marked as a duplicate of a question on calling a Bash command. I daresay anyone familiar with programming should be aware that "calling a Bash command" is vastly different from sucking down a resource by HTTP and sending its output to another program.

Does anyone have sample code showing how to achieve this kind of thing in Ruby:

curl http://stackoverflow.com | wc

I know I could use system, but would ideally like to keep it pure Ruby using IO.pipe or whatnot.

like image 480
mahemoff Avatar asked May 12 '26 23:05

mahemoff


1 Answers

Use Open3::pipeline method. For example:

require 'open3'

Open3.pipeline(['curl', 'http://stackoverflow.com'],
               ['wc'])
like image 171
falsetru Avatar answered May 15 '26 13:05

falsetru



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!