I have to run some shell commands where the user gives the input. I found one way which seemed secure: system *%W(ls #{file}) [here].
I need to get the output of that command, so I cant just use system. Is there a way to sanitize the command for backticks `` or for %x[]?
You want
IO::popeninstead ofsystem. You can still pass an array of strings to invoke the command without a shell, and you canreadfrom the resulting IO object.If you want to read stderr too, then use the
open3module instead of IO.