Paste strings in `Cmd`

To avoid XY problem, I’ll describe the problem that needs to be solved first.

After building a JLL package, one can use

run(`$(product_name()) $args`)

to wrap an executable. (Then use execute to collect the results as describe here)

However, when passing args to the command,

args = "--opt file"
`cmd $args`

I get cmd '--opt file' rather than cmd --opt file, which could result in error.

So, what is the right way to do it?

Thanks in advance!

Use args = `--opt file` . See for example

julia> args = "hello world"
"hello world"

julia> dump(`echo $args`)
Cmd
  exec: Array{String}((2,))
    1: String "echo"
    2: String "hello world"
  ignorestatus: Bool false
  flags: UInt32 0x00000000
  env: Nothing nothing
  dir: String ""
  cpus: Nothing nothing

julia> args = `hello world`
`hello world`

julia> dump(`echo $args`)
Cmd
  exec: Array{String}((3,))
    1: String "echo"
    2: String "hello"
    3: String "world"
  ignorestatus: Bool false
  flags: UInt32 0x00000000
  env: Nothing nothing
  dir: String ""
  cpus: Nothing nothing

If args is a String, when interpolated it’s kept all together, like what you’d expect from strings, if instead it’s a Cmd, when interpolated it’s broken down in its components.

2 Likes