While I agree that shelling out is inherently problematic, all of these examples make me think ruby really ought to provide a shell-out wrapper that provides many of the partial solutions that "nobody does" for you. If not in stdlib, we could write easily a gem (that nobody would use, heheh).
result = shell_out('find ? -type f -print0 | xargs -0 grep foo | wc -l', dir_path)
Would automatically `Shellwords.shellescape` interpolated variables, same as ActiveRecord does (hash params could be supported too). Would by default automatically `set -o pipefail` for you too, and perhaps even by default raise for a non-succesful outcome. All of these defaults could hypothetically be changed by option arguments.In fact, I wonder if there already is a gem that does this, that nobody uses? :) If not, it makes me want to write one just for fun, link back to OP as explanation of why you want this. That still nobody would use except me, heh.
Shelling out is a hacky solution nonetheless, with a terrible performance profile, but there are reasons people use it anyway, and a wrapper like this could take care of many common gotchas.