Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

odin run . -- <args> incorrectly forwards arguments on Windows #4393

Open
clindholm opened this issue Oct 18, 2024 · 3 comments
Open

odin run . -- <args> incorrectly forwards arguments on Windows #4393

clindholm opened this issue Oct 18, 2024 · 3 comments

Comments

@clindholm
Copy link

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:

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.

@flysand7
Copy link
Contributor

flysand7 commented Oct 19, 2024

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.

image

image

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.

@clindholm
Copy link
Author

Good points!
I should've said that I did test in different shells and that the problem shows up in all of them.

But, I did forget to check with the actual executable, I was just sure I'd seen the problem there as well but lo and behold - no issues!

Which is great news, but a little embarrassing. At least we know that the bug is just a tiny dev annoyance then.

Thanks for setting me straight @flysand7 😆

This could probably be closed? It is still a bug, but probably not worth spending much time on, I guess.

@laytan
Copy link
Collaborator

laytan commented Oct 19, 2024

Still a bug in the way odin run forwards arguments so I won't close it

@laytan laytan changed the title os.args parses \ incorrectly on Windows odin run . -- <args> incorrectly forwards arguments on Windows Oct 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants