Interpolating commands into commands is a useful pattern as well: cmd = `convert` if haskey(opts, :density) cmd = `$cmd -density $(opts[:density])` end if haskey(opts, :depth) cmd = `$cmd -depth $(opts[:depth])` end run(cmd)
On Thu, Nov 3, 2016 at 12:21 PM, Yichao Yu <yyc1...@gmail.com> wrote: > On Thu, Nov 3, 2016 at 12:17 PM, Andre Bieler <andre.biele...@gmail.com> > wrote: > > I want to generate a command for imagemagick and use options loaded from > a > > file. > > So the number of utilized options is not known beforehand. > > > > An example might look like: > > > > convert -density 300 somefile.pdf -depth 10 somefile.jpeg > > > > It is easy to generate the string above, but when interpolating it > > into a command it gets quoted because of the spaces. > > > > So > > > > s = "convert -density 300 somefile.pdf -depth 10 somefile.jpeg" > > run(`$s`) > > > > does not work. Is there an easy way to omit quoting? > > Or how to generate the command when having vectors of keyword : value > pairs > > such as > > > > kw = ["-density", "-depth"] > > vals = [300, 8] > > > > (assuming for now that all these options simply follow each other in one > > place of > > the command) > > > > Thanks for the help. > > Interpolate in the command and not the string > > you can do `command $option` where option is a string or an array of > string. > > > > > Andre >