script.exs source:
IO.inspect System.argv
running with:
elixir script.exs --options=25,26
Environment
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?
lud
2
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.
- 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”], , }
- 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”], }
2 Likes