3

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.

mahemoff
  • 44,526
  • 36
  • 160
  • 222
  • Please describe in detail what is different in those two questions, I doubt this will be reopened just because you say they are different ;-) – Uli Köhler Mar 02 '14 at 14:26
  • 1
    Looks like people are re-opening it. It's so obvious from the titles, I can't see how anyone versed in programming could make this blunder, let alone 5 mods confirming it. "Pipe URL contents" versus "Call Bash command". The most generous thing I could say is that the first one is vaguely a superset of this question, which would be like saying "How do I read a file in C" is a duplicate of "How do I write a C program". – mahemoff Mar 02 '14 at 15:22
  • 1
    However, "How do I write a C program" would be closed, because it is not a valid question for SO. Even if there is only one sentence (e.g. `The other question does not ask about pipes`), you would not believe how much *easier* it was to vote. I *really* dislike people asking for reopen *because they say the duplicate is unrelated*. Not because it is invalid in any case, but *because anybody does it, even if it would be easy to describe*. So, please do us the favour and *describe* what is so obvious to you, because the close should have told you that it is not nearly as obvious for others! – Uli Köhler Mar 02 '14 at 15:27
  • 1
    Done. Understand why the "it's true because I say it's true" explanation was pointless, I just felt in this case it was incredibly self-evident. But I take your point and it's updated. – mahemoff Mar 02 '14 at 15:39
  • 1
    Thank you very much ;-) For the record, I also support your point, voted to reopen before you edited that in and hope you'll get the missing reopen votes! – Uli Köhler Mar 02 '14 at 15:44
  • 1
    Thanks. I don't especially care about this question. I just find the whole thing disconcerting as it shows a serious problem with Stack moderation that people blindly confirm what is blatantly a blundered moderation action. – mahemoff Mar 02 '14 at 15:50

1 Answers1

5

Use Open3::pipeline method. For example:

require 'open3'

Open3.pipeline(['curl', 'http://stackoverflow.com'],
               ['wc'])
falsetru
  • 357,413
  • 63
  • 732
  • 636