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,
@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.
I am indeed on Windows. I should have mentioned that, but it actually didn’t occur to me since elixir works as expected. I am on Windows 11 using PowerShell. My Elixir version is:
I typically bounce between Windows and WSL2 and sometimes Docker for my development, depending on what I’m doing.
Does anyone know why elixir works and mix doesn’t? It doesn’t seem to be solely a Windows problem if one works as expected, although I seem to recall running into something similar to this before with mix. Since Elixir supports Windows, I think this should probably work or be documented why. It would be great to understand why it doesn’t work. I haven’t read through the elixir and mix scripts in detail on Windows.