Command line arguments parsing problem / How can i pass 2 arguments for an option?

script.exs source:

IO.inspect System.argv

running with:

elixir script.exs --options=25,26

Environment

  • Elixir & Erlang/OTP versions (elixir --version):
    Erlang/OTP 21 [erts-10.3] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1]
    Elixir 1.11.1 (compiled with Erlang/OTP 21)

  • Operating system: Windows 10

Current behavior

Output:
[“–options”, “25”, “26”]

Expected behavior

Output:
[“–options”, “25,26”]

So, when i try to

OptionParser.parse(System.argv, strict: [options: :string])

it gives me only [options: “25”] and i want [options: “25,26”].
Is this a normal behavior?

It does not seem normal, no.

With this version: Elixir 1.11.0 (compiled with Erlang/OTP 23)

and this script :

# ttt.exs

System.argv()
|> IO.inspect(label: "argv")

OptionParser.parse(System.argv(), strict: [options: :string])
|> IO.inspect(label: "parsed")

I get those results:

$ elixir ttt.exs --options=25,26
argv: ["--options=25,26"]
parsed: {[options: "25,26"], [], []}

But I am currently on MacOS. What if you run as elixir script.exs --options "25,26" ?

Experimented a little and found a source of the problem - PowerShell.

  1. Through cmd.exe:

elixir ttt.exs --options 25,26
argv: [“–options”, “25”, “26”]
parsed: {[options: “25”], [“26”], }
but this works:
elixir ttt.exs --options “25,26”
argv: [“–options”, “25,26”]
parsed: {[options: “25,26”], , }

  1. Through PowerShell which is default on Win10:

elixir ttt.exs --options 25,26
argv: [“–options”, “25”, “26”]
parsed: {[options: “25”], [“26”], }
and this does not work either:
elixir ttt.exs --options “25,26”
argv: [“–options”, “25”, “26”]
parsed: {[options: “25”], [“26”], }

1 Like