mahemoff
mahemoff

Reputation: 46389

Ruby: PIpe URL contents to bash command

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.

Upvotes: 3

Views: 238

Answers (1)

falsetru
falsetru

Reputation: 369074

Use Open3::pipeline method. For example:

require 'open3'

Open3.pipeline(['curl', 'http://stackoverflow.com'],
               ['wc'])

Upvotes: 5

Related Questions