I've occasionally needed to pipeline some processes in Ruby, especially when doing sysadmin-type tasks. You can always do:

system "foo | bar"

but that gets interpreted by the shell. That can be a problem when you need to
include filenames that could have all kinds of nastiness including spaces,
semicolons, exclamation points, etc. You should be shaking in your boots about
now.

Well, for single processes, it's easy:

system "foo", arg1, arg2

But if you want to pipe them together it's a bit more difficult. I came up with
this solution, and it seems to be working well in my "convert my cool music
collection into a lame (wink) format my car stereo can understand" script:

If you want to look for some inspiration for metaprogramming constructs to do nifty shell-like things, look no further than scsh, the Scheme shell. It also has the distinction of having the most hilarious Acknowledgements section of any reference manual I’ve ever seen.

To run the equivalent of “foo | bar “, you’d do (| (foo arg1 arg2) (bar arg1 arg2)). Your syntax seems pretty similar, except you have to manually parse the command lines into strings. That’s just the tip of the scsh iceberg, though, so I recommend taking a look at at least the Process Forms section of the manual for inspiration.