Ronan Lopes Ronan Lopes - 3 months ago 22
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|


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|


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

does anyone knows how I fix it? Thanks!


The arguments need to be separate from the command. Try

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