# Interpolating multiple parameters into a Cmd

**URL:** <https://discourse.julialang.org/t/interpolating-multiple-parameters-into-a-cmd/97709>\
**Category:** General Usage\
**Tags:** cmd\
**Created:** [April 20, 2023, 6:47am UTC](https://discourse.julialang.org/t/interpolating-multiple-parameters-into-a-cmd/97709 "2023-04-20T06:47:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bernhard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bernhard/32/2619_2.png) [@bernhard](https://discourse.julialang.org/u/bernhard)\
**Post date:** [April 20, 2023, 6:47am UTC](https://discourse.julialang.org/t/interpolating-multiple-parameters-into-a-cmd/97709/1 "2023-04-20T06:47:56Z")

</div>

Thank you Steven.  
Raising this topic from the dead.

In my scenario, concatenation of the command fails, as I get single apostrophes in the command that I don’t want, see my first comment.

Any ideas how I can avoid this?  
Hardcoding the parameters (second run command) is a workaround (but obviously I loose much flexibility)

```julia
infile = raw"C:\temp\t\in.flac"
outfile = raw"C:\temp\t\out.mp3"

    @assert splitext(infile)[2] == ".flac"
    parms = "-ar 48000 -ab 320k -y -ac 2 -vn -map_metadata 0 -id3v2_version 3"
    cmd = `ffmpeg -i $infile $parms $outfile`
    run(cmd)
    #THIS FAILS, because there are single quotes in the parameters, how can I get rid of them?  
    `ffmpeg -i 'C:\temp\t\in.flac' '-ar 48000 -ab 320k -y -ac 2 -vn -map_metadata 0 -id3v2_version 3' 'C:\temp\t\out me mo.mp3'`

    cmd = `ffmpeg -i $infile -ar 48000 -ab 320k -y -ac 2 -vn -map_metadata 0 -id3v2_version 3 $outfile`
    #run(cmd) #works but prints to stdout
    rs = run(pipeline(cmd, stdout=devnull, stderr=devnull))
    @assert rs.exitcode == 0
    @assert rs.termsignal == 0

```

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [April 20, 2023, 3:10pm UTC](https://discourse.julialang.org/t/interpolating-multiple-parameters-into-a-cmd/97709/2 "2023-04-20T15:10:19Z")

</div>

I split this into a new topic, which is better than attaching to an ancient thread.

> [@bernhard](#):
>
> `cmd = `ffmpeg -i $infile $parms $outfile``

Your mistake here is that `$parms`, where `parms` is a `String`, tries to interpolate `parms` as a _single_ argument, not as a list of multiple arguments. Doing this robustly is one of the reasons why `Cmd` is nice and [shelling out sucks](https://julialang.org/blog/2012/03/shelling-out-sucks/) — Julia’s `Cmd` doesn’t run into trouble even if `parms` contains spaces, quotes, or other shell metacharacters.

However, in your case, you _want_ multiple arguments, i.e. you want the spaces in `parms` to be treated as metacharacters. (You’re maybe thinking of this as launching a shell, which it isn’t.) In that case, the right thing is simply to make `parms` an _array_ of arguments:

```julia
parms = ["-ar", "48000", "-ab", "320k", "-y", "-ac", "2", "-vn", "-map_metadata", "0", "-id3v2_version"]
cmd = `ffmpeg -i $infile $parms $outfile`

```

or equivalently

```julia
parms = split("-ar 48000 -ab 320k -y -ac 2 -vn -map_metadata 0 -id3v2_version 3", ' ')
cmd = `ffmpeg -i $infile $parms $outfile`

```

---

<div class="post-metadata">

**Author:** ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)\
**Post date:** [April 20, 2023, 3:32pm UTC](https://discourse.julialang.org/t/interpolating-multiple-parameters-into-a-cmd/97709/3 "2023-04-20T15:32:39Z")

</div>

or equivalently

```julia
parms = `-ar 48000 -ab 320k -y -ac 2 -vn -map_metadata 0 -id3v2_version 3`
cmd = `ffmpeg -i $infile $parms $outfile`

```
