Does Ruby ship with a function/method to run a command and capture it's output without risking command injection.
For example:
out = `ls #{directory}`
would capture the output I want, but is insecure.
system("ls", directory)
is safer (as far as I know), but I can't capture it's output.
Is there some equivalent to Python's out = call(['ls', directory])?
Edit for @Eric Duminil
irb(main):001:0> RUBY_DESCRIPTION
=> "ruby 2.1.8p440 (2015-12-16 revision 53160) [x86_64-linux]"
irb(main):002:0> Shellwords
NameError: uninitialized constant Shellwords
from (irb):2
from /apollo/env/SDETools/ruby2.1.x/bin/irb:15:in `<main>'
irb(main):003:0> require "shellwords"
=> true
irb(main):004:0> Shellwords
=> Shellword
Kernel#systemaccepts the same options asKernel#spawnyou can specify anIOobject for the output See Docs