Ronan Lopes Ronan Lopes - 2 months ago 6
Ruby Question

Ruby - Open3 popen3 function sanitized

would like to run a system command on ruby using popen3 function from Open3. It would be something like:

pdf2htmlEX --zoom 1.3 ~/test.pdf


As the filename will be passed by params, I would like to sanitize it. if run, for example:

Open3.popen3("pdf2htmlEX --zoom 1.3 ~/test.pdf") do |stdin, stdout, stderr, wait_thr|

end


The code works fine, but when I try to separate the argument (as the functions suggests that way it would be escaped), something like:

Open3.popen3("pdf2htmlEX --zoom 1.3", "~/test.pdf") do |stdin, stdout, stderr, wait_thr|

end


it gives me the error: No such file or directory - pdf2htmlEX --zoom 1.3

does anyone knows how I fix it? Thanks!

Answer

The arguments need to be separate from the command. Try

Open3.popen3("pdf2htmlEX", "--zoom 1.3", "~/test.pdf")...

Comments