bmitc
How to pass strings containing commas to a script using `mix run`?
Apologies if I am missing something silly, but I am unable to figure this out. I am trying to run an Elixir script using mix run, and I want to pass a single arbitrary string to it.
A sample script, say scripts/string_parser.exs looks like this:
System.argv()
|> IO.inspect()
This example only contains the relevant parts. Here’s some sample runs of the script:
> mix run scripts/string_parser.exs '{:ok}'
["{:ok}"]
> mix run scripts/string_parser.exs '{:ok,:test}'
["{:ok", ":test}"]
> mix run scripts/string_parser.exs '{:ok\,:test}'
["{:ok\" :test}"]
> mix run scripts/string_parser.exs "{:ok,:test}"
["{:ok", ":test}"]
> mix run scripts/string_parser.exs "{:ok\,:test}"
["{:ok\" :test}"]
How do I pass a string that contains a , as a command line argument to mix run <script>?
Note: This issue does not occur for running a script with elixir <script> <arguments>. For example,
> elixir scripts/string_parser.exs '{:ok, :test}'
["{:ok, :test}"]
and all the other variations work as expected.
This either seems like a bug or I’m missing something.
Most Liked
cmo
@bmitc are you on Windows by any chance? mix is mix.bat or mix.ps1 and I think you’ll find that passing args on Windows is a nightmare due to the different shells and batch scripts vs PowerShell scripts.
My determination was that it is not worth the effort trying to handle them and built an exe for my release instead of <release>.bat. The Burrito project does something funky to handle the args on Windows too.
You might have better luck doing your dev in WSL.







