2

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[]?

Community
  • 1
  • 1
klump
  • 3,191
  • 2
  • 22
  • 26

2 Answers2

3

You want IO::popen instead of system. You can still pass an array of strings to invoke the command without a shell, and you can read from the resulting IO object.

If you want to read stderr too, then use the open3 module instead of IO.

glenn jackman
  • 223,850
  • 36
  • 205
  • 328
0

What kind of shell commands are you running that Ruby cannot support? If you are listing files, use Dir

Andrew Grimm
  • 74,534
  • 52
  • 194
  • 322
kurumi
  • 24,217
  • 4
  • 43
  • 49
  • i was using ls just as an exsample, i want to use a mix of selfwritten programms and unix programms, i am using the ruby File, Dir and FileUtils classes :P – klump Mar 20 '11 at 13:15