You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import "core:os"
import "core:fmt"
main :: proc() {
for a, i in os.args[1:] {
fmt.println(i, a)
}
}
Let's say I run it with odin run . -- test\ test test
I'd expect:
0 test\
1 test
2 test
Instead I get:
0 test" test test
odin run . -- test\ test\ test gives:
0 test" test"
1 test
Quoting makes no difference: odin run . -- "test\" 'test\' test still gives:
0 test" test"
1 test
Escaping does work: odin run . -- test\\ test
0 test\
1 test
But still, that's not necessary with cli programs in general on Windows, and it's not consistent - escaping only escapes the final backslash: odin run . -- te\\st\\ test
0 te\\st\
1 test
I tried looking at the code for os.args but I haven't worked with the Windows API so I couldn't easily tell what's going on there. I'll still take a closer look, but I thought if I report it someone else would have a fix much faster (or at all 😄).
Just in case, I also tried similar code with nodejs to make sure it's not something weird with my setup.
The text was updated successfully, but these errors were encountered:
Which shell you're using? cmd, powershell or pwsh? Does the problem reproduce on all three of them?
Does the problem reproduce if instead run -- <args>, you first did build and then run the actual executable with the flags?
These are the things I would ask, because I myself have run into the issue with command line arguments being inconsistent across shells, and sometimes depending on whether -- is used within the command line.
E.g. below I have saved up two screenshots, of a program that prints os.args one by one, being ran from cmd and pwsh, with and without -- as one of the arguments.
I'm asking because Odin performs minimal possible parsing of the arguments. It actually doesn't parse the command line arguments, as far as I know and uses windows API to parse them for us. Which may not be our fault per se... but still something worth investigating or coming up with a better solution maybe.
Context
Odin: dev-2024-10-nightly:af9ae48
OS: Windows 10 Home Basic (version: 22H2), build 19045.5011
CPU: AMD Ryzen 7 5800X 8-Core Processor
RAM: 16305 MiB
Backend: LLVM 18.1.8
Given the following program:
Let's say I run it with
odin run . -- test\ test test
I'd expect:
Instead I get:
odin run . -- test\ test\ test
gives:Quoting makes no difference:
odin run . -- "test\" 'test\' test
still gives:Escaping does work:
odin run . -- test\\ test
But still, that's not necessary with cli programs in general on Windows, and it's not consistent - escaping only escapes the final backslash:
odin run . -- te\\st\\ test
I tried looking at the code for os.args but I haven't worked with the Windows API so I couldn't easily tell what's going on there. I'll still take a closer look, but I thought if I report it someone else would have a fix much faster (or at all 😄).
Just in case, I also tried similar code with nodejs to make sure it's not something weird with my setup.
The text was updated successfully, but these errors were encountered: