Error setting mixed type Cmd environment

The following command results in error because it has mixed strings and integers.

Cmd(ampl PF.run,env=(“param1”=>1,“param2”=>“abc”))

ERROR: MethodError: no method matching byteenv(::Tuple{Pair{String, Int64}, Pair{String, String}})

Closest candidates are:
  byteenv(::Nothing)
   @ Base cmd.jl:249
  byteenv(::Union{AbstractArray{Pair{T, V}, 1}, Tuple{Vararg{Pair{T, V}}}}) where {T<:AbstractString, V}
   @ Base cmd.jl:250
  byteenv(::AbstractDict)
   @ Base cmd.jl:247
  ...

Stacktrace:
 [1] Cmd(cmd::Cmd; ignorestatus::Bool, env::Tuple{…}, dir::String, cpus::Nothing, detach::Bool, windows_verbatim::Bool, windows_hide::Bool)
   @ Base .\cmd.jl:30
 [2] top-level scope
   @ REPL[20]:1
Some type information was truncated. Use `show(err)` to see complete types.

If the parameters are exclusively integers or exclusively strings then it appears to work ok. How to avoid this issue? I am running Julia 1.10.7.

You can use a Dictionary instead of a Tuple{Vararg{Pair}}:

julia> run(Cmd(`sh -c "echo \$param1 \$param2"`, env=("param1"=>1, "param2"=>"abc")));
ERROR: MethodError: no method matching byteenv(::Tuple{Pair{String, Int64}, Pair{String, String}})
...

julia> run(Cmd(`sh -c "echo \$param1 \$param2"`, env=Dict("param1"=>1, "param2"=>"abc")));
1 abc

Can you submit an issue? This should be made to work since all values are just converted to strings.

I created an issue as suggested.

1 Like