by jrochkind1 · 11y ago · 0 comments
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.